用swing写了一个GUI,在关闭窗口时,使得窗口在某一条件下,不关闭,即取消关闭窗口的动作。
| /* * mFrame2.java * * Created on 2005年7月4日, 下午1:12 */ package DialogExample; /** * * @author Administrator */ public class mFrame2 extends javax.swing.JFrame { /** Creates new form mFrame2 */ public mFrame2() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() { buttonGroup1 = new javax.swing.ButtonGroup(); buttonGroup2 = new javax.swing.ButtonGroup(); buttonGroup3 = new javax.swing.ButtonGroup(); jPanel1 = new javax.swing.JPanel(); jTextField1 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); jPanel1.setBorder(new javax.swing.border.TitledBorder("Tilte Broder")); jTextField1.setText("jTextField1"); jPanel1.add(jTextField1); jButton1.setText("jButton1"); jPanel1.add(jButton1); getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH); pack(); } /** Exit the Application */ private void exitForm(java.awt.event.WindowEvent evt) { if(true) { System.out.println("hello exiting"); // return; } //System.exit(0); } /** * @param args the command line arguments */ public static void main(String args[]) { new mFrame2().show(); } // Variables declaration - do not modify private javax.swing.ButtonGroup buttonGroup1; private javax.swing.ButtonGroup buttonGroup2; private javax.swing.ButtonGroup buttonGroup3; private javax.swing.JButton jButton1; private javax.swing.JPanel jPanel1; private javax.swing.JTextField jTextField1; // End of variables declaration } 关键的代码是 setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); private void exitForm(java.awt.event.WindowEvent evt) { if(true) { System.out.println("hello exiting"); // return; } //System.exit(0); } 此程序单击“×”之后什么也不做,只是在console中输出"hello exiting" |
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
相关专题
- Java环境安装配置 (5650篇文章)
- Java编程开发手册 (8301篇文章)
- J2SE综合:浅谈java程序发布之 jre 篇 (11次浏览)
- JAVA代码中使用魔法数值 (8次浏览)
- Hibernate缓存管理 (6次浏览)
- JAVA代码应该流畅和结构化 (5次浏览)
- Java JVM设置对性能的影响 (4次浏览)
- 开发框架:深入了解 Struts Validator (3次浏览)
- Java中的通信机制及与C/C API的集成 (1次浏览)
- 用Hibernate实现领域对象的自定义字段 (1次浏览)
- Java语言入门 简述Java语言回收机制 (0次浏览)
- 2008年Java开发者最迫切的五个期望 (0次浏览)



