当前位置: 技术问答>java相关
关于程序的退出。
来源: 互联网 发布时间:2015-09-01
本文导语: setDefaultCloseOperation(JFrame.EXIT_ON_CLSOE)和下面的函数等效吗? public void windowClosing(WindowEvent e){ System.exit(0); } | windowClosing public void windowClosing(WindowEvent e) Invoke...
setDefaultCloseOperation(JFrame.EXIT_ON_CLSOE)和下面的函数等效吗?
public void windowClosing(WindowEvent e){
System.exit(0);
}
public void windowClosing(WindowEvent e){
System.exit(0);
}
|
windowClosing
public void windowClosing(WindowEvent e)
Invoked when the user attempts to close the window from the window's system menu. If the program does not explicitly hide or dispose the window while processing this event, the window close operation will be cancelled.
--------------------------------------------------------------------------------
windowClosed
public void windowClosed(WindowEvent e)
Invoked when a window has been closed as the result of calling dispose on the window.
public void windowClosing(WindowEvent e)
Invoked when the user attempts to close the window from the window's system menu. If the program does not explicitly hide or dispose the window while processing this event, the window close operation will be cancelled.
--------------------------------------------------------------------------------
windowClosed
public void windowClosed(WindowEvent e)
Invoked when a window has been closed as the result of calling dispose on the window.
|
应该一样!
|
是等效的。
public void windowClosing(WindowEvent e){
System.exit(0);
}
是重载了JFrame的windowClosing()方法,当捕获到关闭窗口的事件时,就调用exit()方法。setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)的作用也是如此。看下面这段:
EXIT_ON_CLOSE (defined in JFrame): Exit the application using the System exit method. Use this only in applications.
public void windowClosing(WindowEvent e){
System.exit(0);
}
是重载了JFrame的windowClosing()方法,当捕获到关闭窗口的事件时,就调用exit()方法。setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)的作用也是如此。看下面这段:
EXIT_ON_CLOSE (defined in JFrame): Exit the application using the System exit method. Use this only in applications.