資源描述:
《2012模態(tài)對話框與非模態(tài)對話框》由會員上傳分享,免費在線閱讀,更多相關內容在教育資源-天天文庫。
1、模態(tài)對話框與非模態(tài)對話框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("模態(tài)顯示對話框");jb1.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEve
3、nte){do_button01(e);}});JButtonjb2=newJButton("非模態(tài)顯示對話框");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("模態(tài)顯示對話框");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("模態(tài)顯示對話框");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();}}