博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java窗口内容如何复制_求助Java窗口菜单如何实现复制粘贴剪切等功能(内附源代码)...
阅读量:1544 次
发布时间:2019-04-21

本文共 3424 字,大约阅读时间需要 11 分钟。

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

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){}}}}

转载地址:http://oerdy.baihongyu.com/

你可能感兴趣的文章
认识Java
查看>>
java中非静态、静态方法的调用、方法中调用方法
查看>>
Java中的访问权限修饰符、各种变量、static、final等关键字,一直混淆的整理(未完)
查看>>
宋红康的快捷键包描述(idea导入类似eclipse的)keymap-shkstart.jar
查看>>
IDEA默认的快捷键整理!!
查看>>
超宽带雷达P440?雷达的快时间慢时间是什么意思?
查看>>
教育授权certificate used to sign the license
查看>>
从内存解释:方法传参(基本数据类型、引用数据类型(对象、数组、String类型)),原值是否改变?
查看>>
java中数组为空和数组长度为0的区别
查看>>
SecureCRT连接不上虚拟机
查看>>
为什么在创建线程时,更推荐用实现Runnable接口的方法?而不是继承Thread类的方法?
查看>>
从100万个数中找出最大的前100个数-最小堆、分块
查看>>
并发下的ArrayList、HashMap
查看>>
仿牛客社区项目2.2登录模块——开发注册功能
查看>>
仿牛客社区项目2.3登录模块——会话管理Cookie、Session
查看>>
仿牛客社区项目2.4登录模块——生成验证码
查看>>
JDK-JRE-JVM关系、Java语言跨平台
查看>>
仿牛客社区项目2.5登录模块———登录退出功能
查看>>
仿牛客社区项目3.2——发布帖子(异步通信技术AJAX)
查看>>
仿牛客社区项目3.3——帖子详情(普通功能)
查看>>