smw*_*dia 4 java swing jframe windowlistener
WindowConstants 定义如下:
public interface WindowConstants
{
public static final int DO_NOTHING_ON_CLOSE = 0;
public static final int HIDE_ON_CLOSE = 1;
public static final int DISPOSE_ON_CLOSE = 2;
public static final int EXIT_ON_CLOSE = 3;
}
Run Code Online (Sandbox Code Playgroud)
JFrame 定义如下:
public class JFrame extends Frame implements WindowConstants,
Accessible,
RootPaneContainer,
TransferHandler.HasGetTransferHandler
{
/**
* The exit application default window close operation. If a window
* has this set as the close operation and is closed in an applet,
* a <code>SecurityException</code> may be thrown.
* It is recommended you only use this in an application.
* <p>
* @since 1.3
*/
public static final int EXIT_ON_CLOSE = 3;
Run Code Online (Sandbox Code Playgroud)
为什么EXIT_ON_CLOSE要重新定义?而且由于它final在WindowConstants界面中,如何重新定义?
在Java 1.3中,当全部添加时,EXIT_ON_CLOSE仅JFrame与其他实现有关,而与其他实现无关WindowConstants.因此 - 它不存在于其中WindowConstants并在其中定义JFrame.其他3个XXX_ON_CLOSE选项在界面中.(英文Javadoc不再在线,但仍然可以下载,所以这里没有参考.如果你搜索"WindowConstants Java 1.3"你会得到一个日文版的Javadoc - 但由于页面结构相同,你仍然可以看到要点)
后来(1.4)移动到了WindowConstants,但JFrame由于兼容性问题,该字段未被删除.
那里没有重新定义.发生的事是阴影.即该JFrame领域隐藏(但不消除)该WindowConstants领域.