日期:2014-05-20 浏览次数:20813 次
public class NewJFrame extends javax.swing.JFrame { /** * Auto-generated main method to display this JFrame */ public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { final NewJFrame inst = new NewJFrame(); inst.setLocationRelativeTo(null); inst.setVisible(true); inst.setTitle("主窗口"); inst.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { if (e.equals(inst)) System.exit(0); } }); NewJFrame inst2 = new NewJFrame(); inst2.setLocationRelativeTo(null); inst2.setVisible(true); inst.setTitle("子窗口"); } }); } public NewJFrame() { super(); initGUI(); } private void initGUI() { try { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); pack(); setSize(400, 300); } catch (Exception e) { e.printStackTrace(); } } }
------解决方案--------------------
自己看看
JFrame的
EXIT_ON_CLOSE
DISPOSE_ON_CLOSE
HIDE_ON_CLOSE
这三个有什么差别,试验一下。