窗口关闭 setDefaultCloseOperation的四种关闭方式的区别
默认关闭状态:
JFrame.class中: private int defaultCloseOperation =HIDE_ON_CLOSE;
因此,在你点击关闭按钮的时候,默认情况下,关闭窗口,只隐藏界面,不释放占用的内存。
点击窗口右上角关闭,四种关闭方式:
1.this.setDefaultCloseOperation(0);
DO_NOTHING_ON_CLOSE,(在你点击关闭按钮的时候,不会被关闭,)不执行任何操作。
2.this.setDefaultCloseOperation(1);
HIDE_ON_CLOSE,(当你点击关闭按钮的时候,不会释放内存,只是隐藏该界面,没有真正的关闭,还占有资源)只隐藏界面,setVisible(false)。
3.this.setDefaultCloseOperation(2);
DISPOSE_ON_CLOSE,点击关闭按钮的时候,隐藏并释放窗体,dispose(),当最后一个窗口被释放后,则程序也随之运行结束。
4.this.setDefaultCloseOperation(3);
EXIT_ON_CLOSE,直接关闭应用程序,System.exit(0)。一个main函数对应一整个程序。**