java窗口内容如何复制_求助Java窗口菜单如何实现复制粘贴剪切等功能(内附源代码)...
发布日期:2021-06-24 16:15:38 浏览次数:4 分类:技术文章

本文共 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){}}}}

转载地址:https://blog.csdn.net/weixin_33758343/article/details/114865670 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:盾神与砝码称重java_[蓝桥杯][算法提高VIP]盾神与砝码称重
下一篇:java factory用法_怎样使用Java实现Factory设计模式

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年03月29日 00时32分35秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

iBATIS&Spring合奏(二)--Flex前端融合 2019-04-28
iBATIS&Spring合奏(三)--事务&动态SQL 2019-04-28
C++核心准则C.48:如果构造函数需要用常数初始化成员,使用类内初始化器更合适 2019-04-28
C++核心准则C.49:构造函数中应该做的是初始化而不是赋值 2019-04-28
C++核心准则C.50:如果在构造过程中需要“虚行为”,使用工厂函数 2019-04-28
C++核心准则C.51:使用委托构造函数实现所有构造函数的共通动作 2019-04-28
C++核心准则C.52:合理使用继承的构造函数 2019-04-28
基于Chrome浏览器的前端调试 2019-04-28
Python:Flask部署Nginx、gunicorn、gevent、flask、supervisor 2019-04-28
【李宏毅2020 ML/DL】补充:Ensemble: Bagging, Boosting, Adaboost, Gradient Boosting, Stacking 2019-04-28
【Computer Organization笔记24】光盘,FLASH MEMORY,本单元总结 2019-04-28
【必收藏】台大李宏毅老师课程 | 资源汇总、笔记总结与索引 2019-04-28
【Computer Organization笔记25】I/O:程序直接控制,程序中断方式,直接存储访问(DMA),通道控制方式 2019-04-28
【Computer Organization笔记26】总线 bus :多个部件之间进行数据传送的共享通道,总线设计 - 总线仲裁、数据传输模式、提高总线性能 2019-04-28
WSL2 下的 Docker 配置,使用网易云镜像 + 更改 docker 文件系统(否则无法 apt update) 2019-04-28
【Computer Organization笔记27】接口电路和外部设备 2019-04-28
【Computer Organization笔记28】总复习 2019-04-28
【Computer Organization笔记29】大作业展示 2019-04-28
个人总结的【LaTeX】超高频特殊符号表(仅33个符号)+复杂公式速写解决方案,请查收! 2019-04-28
一年前我在知乎上提了个愚蠢的问题:如何入门 Linux ? 2019-04-28