日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java 两个窗口 贴_求助Java窗口菜单如何实现复制粘贴剪切等功能(内附源代码)...

發布時間:2024/1/23 java 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 两个窗口 贴_求助Java窗口菜单如何实现复制粘贴剪切等功能(内附源代码)... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

該樓層疑似違規已被系統折疊?隱藏此樓查看此樓

if(e.getActionCommand()=="進入注冊") {new CommFrame();?? }}class HandleClose extends WindowAdapter?? {?? public void windowClosing(WindowEvent e)?? {?? Frame f=(Frame)(e.getWindow());?? ConfirmDlg confirm=new ConfirmDlg(f);?? if(confirm.ans){f.dispose();System.exit(0);}?? }?? }

class HandleWin extends WindowAdapter{public void windowClose(WindowEvent e){Frame f=(Frame)(e.getWindow());ConfirmDlg confirm=new ConfirmDlg(f);if(confirm.ans){f.dispose();System.exit(0);}}}

class ConfirmDlg implements ActionListener{Dialog dlg;Label message=new Label("是否關閉窗口");Button btnY=new Button("是");Button btnN=new Button("否");Panel p1=new Panel();Panel p2=new Panel();boolean ans;ConfirmDlg(Frame own){btnY.addActionListener(this);btnN.addActionListener(this);dlg=new Dialog(own,"確認對話框",true);p1.add(message);p2.add(btnY);p2.add(btnN);dlg.add(p1,BorderLayout.NORTH);dlg.add(p2,BorderLayout.SOUTH);dlg.setSize(200,100);dlg.setVisible(true);}?? public void actionPerformed(ActionEvent e)?? {?? dlg.dispose();?? if(e.getActionCommand()=="是")?? ans=true;?? else?? ans=false;?? }}

class HandleAct implements ActionListener{MyMenuFrame Frame;HandleAct(MyMenuFrame f){Frame=f;}public void actionPerformed(ActionEvent e){?? if(e.getActionCommand()=="退出"){?? Frame f=new Frame();?? ConfirmDlg confirm=new ConfirmDlg(f);?? if(confirm.ans){f.dispose();System.exit(0);}?? }elseFrame.textArea.setText(e.getActionCommand());

}}}class InputArea extends Panel implements ActionListener?? {?? File f = null;?? RandomAccessFile out;

TextField name,email,phone;?? Button button;?? InputArea(File f)?? {?? ??? setBackground(Color.cyan);?? this.f=f;?? name=new TextField(12);?? email=new TextField(12);?? phone=new TextField(12);?? button=new Button("錄入");?? button.addActionListener(this);?? add(new Label("輸入姓名:"));?? add(name);?? add(new Label("輸入e_mail:"));?? add(email);?? add(new Label("輸入電話:"));?? add(phone);?? add(new Label("單擊錄入"));?? add(button);?? setVisible(true);?? ?? }

public void actionPerformed(ActionEvent e)?? {?? try?? {?? RandomAccessFile out = new RandomAccessFile(f,"rw");?? if(f.exists())?? {?? long lenth=f.length();?? out.seek(lenth);?? }?? out.writeUTF("姓名:"+name.getText());?? out.writeUTF("email:"+email.getText());?? out.writeUTF("電話:"+phone.getText());?? out.close();}catch(IOException ee){}}}

class CommFrame extends Frame implements ActionListener{File file=null;MenuBar bar;Menu fileMenu;MenuItem 顯示,錄入;TextArea show;InputArea inputMessage;CardLayout card=null;Panel pCenter;CommFrame(){file = new File("通訊錄.txt");錄入=new MenuItem("錄入");顯示=new MenuItem("顯示");bar=new MenuBar();fileMenu=new Menu("菜單選項");fileMenu.add(錄入);fileMenu.add(顯示);bar.add(fileMenu);setMenuBar(bar);錄入.addActionListener(this);顯示.addActionListener(this);inputMessage=new InputArea(file);show=new TextArea(12,20);card=new CardLayout();pCenter=new Panel();pCenter.setLayout(card); pCenter.add("錄入",inputMessage);pCenter.add("顯示",show);add(pCenter,BorderLayout.CENTER);addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){dispose();}} );setVisible(true);setBounds(100,50,420,380);validate();}public void actionPerformed(ActionEvent e){if(e.getSource()==錄入){card.show(pCenter,"錄入");}else if(e.getSource()==顯示){int number=1;show.setText(null);card.show(pCenter,"顯示");try{RandomAccessFile in = new RandomAccessFile(file,"r");String 姓名=null;while((姓名=in.readUTF())!=null){show.append("\n"+number+" "+姓名);show.append(in.readUTF());show.append(in.readUTF());show.append("\n--------------- ");number++;}in.close();}catch(Exception ee){}}}}

總結

以上是生活随笔為你收集整理的java 两个窗口 贴_求助Java窗口菜单如何实现复制粘贴剪切等功能(内附源代码)...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。