如果子窗口设置为
setDefaultCloseOption(Jframe.Exit_ON_CLOSE)的话,关闭子窗口后,父窗口也跟着关闭。
想要只关闭子窗口,方法如下:
子窗口设置为setDefaultCloseOption(JFrame.DISPOSE_ON_CLOSE)
默认关闭状态:JFrame.class中:
private int defaultCloseOperation =HIDE_ON_CLOSE;
因此,默认情况下,关闭窗口,只隐藏界面,不释放占用的内存。
点击窗口右上角关闭,四种关闭方式:
this.setDefaultCloseOperation(0);// DO_NOTHING_ON_CLOSE,不执行任何操作。
this.setDefaultCloseOperation(1);// HIDE_ON_CLOSE,只隐藏界面,setVisible(false)。
this.setDefaultCloseOperation(2);// DISPOSE_ON_CLOSE,隐藏并释放窗体,dispose(),当最后一个窗口被释放后,则程序也随之运行结束。
this.setDefaultCloseOperation(3);// EXIT_ON_CLOSE,直接关闭应用程序,System.exit(0)。一个main函数对应一整个程序。