【发布时间】:2014-12-08 12:40:56
【问题描述】:
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;
}
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;
为什么要重新定义EXIT_ON_CLOSE?而且既然是WindowConstants接口中的final,那怎么重新定义呢?
【问题讨论】:
-
为什么需要重新定义 EXIT_ON_CLOSE?
-
不,我没有重新定义它。而且我认为没有必要。但它是在 JFrame 中定义的,如源代码所示。我只是想知道为什么。
-
因为 API 中默认有 HIDE_ON_CLOSE,所以 EXIT_ON_CLOSE 没有 :-)
-
在 Java5/6 中更改/从 Java5/6(最新 5 和新 6 版本)
-
@mKorbel 我看到
JFrame中有一个private int defaultCloseOperation = HIDE_ON_CLOSE;。但我仍然不明白为什么在JFrame中重新定义了EXIT_ON_CLOSE。
标签: java swing jframe windowlistener