欢迎来到天天文库
浏览记录
ID:37168906
大小:36.50 KB
页数:3页
时间:2019-05-21
《2012模态对话框与非模态对话框》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、模态对话框与非模态对话框JDialogpublicvoidsetModal(Booleanmodal)packagecom.swing.Jlist;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JButton;importjavax.swing.JDialog;importjavax.swing.JFrame;importjavax.swing.UIManager;publicclassTest04ext
2、endsJFrame{publicTest04(){try{UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");}catch(Exceptione){//TODO:handleexception}JButtonjb1=newJButton("模态显示对话框");jb1.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEve
3、nte){do_button01(e);}});JButtonjb2=newJButton("非模态显示对话框");jb2.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstubfor(inti=0;i<10;i++){do_button02(e);}}});jb1.setBounds(103,64,206,30);jb2.setBounds(103,1
4、06,206,30);this.setLayout(null);this.add(jb1);this.add(jb2);this.setVisible(true);this.setBounds(100,100,450,300);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}publicvoiddo_button01(ActionEvente){JDialogjd=newJDialog(this);jd.setModal(true);jd.setSize(300,200);
5、jd.setLocation(200,200);jd.setTitle("模态显示对话框");JButtonjb3=newJButton("关闭");jb3.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstubSystem.exit(1);}});jb3.setBounds(20,20,100,30);jd.setLayout(null);jd.add
6、(jb3);jd.setVisible(true);}publicvoiddo_button02(ActionEvente){JDialogjd=newJDialog(this);jd.setModal(false);jd.setSize(300,200);jd.setLocation(200,200);jd.setTitle("模态显示对话框");JButtonjb3=newJButton("关闭");jb3.addActionListener(newActionListener(){@Overridepublicvoidact
7、ionPerformed(ActionEvente){//TODOAuto-generatedmethodstubSystem.exit(1);}});jb3.setBounds(20,20,100,30);jd.setLayout(null);jd.add(jb3);jd.setVisible(true);}publicstaticvoidmain(String[]args){newTest04();}}
此文档下载收益归作者所有