Java 为什么JFrame重新定义了;退出“U关闭”;它从接口继承的;WindowConstants";?

Java 为什么JFrame重新定义了;退出“U关闭”;它从接口继承的;WindowConstants";?,java,swing,jframe,windowlistener,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

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;

}
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;
JFrame
定义如下:

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;

}
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;

为什么关闭时退出被重新定义?既然它在
WindowConstants
接口中是
final
,怎么能重新定义它呢?

在Java 1.3中,当所有这些都添加到
EXIT\u ON\u CLOSE
中时,它只与
JFrame
相关,而与
WindowConstants
的其他实现无关。因此-它不存在于
WindowConstants
中,而是在
JFrame
中定义的。其他3个
XXX\u ON\u CLOSE
选项在界面中。(英文版Javadoc不再在线,但仍然可以下载,因此此处没有参考。如果搜索“WindowConstants Java 1.3”,您将获得Javadoc的日文版本-但由于页面结构相同,您仍然可以看到要点)

后来(1.4)移动到
WindowConstants
,但是由于兼容性问题,该字段未从
JFrame
中删除


这里没有重新定义。正在发生的是。也就是说,
JFrame
字段隐藏(但不消除)了
WindowConstants
字段。

为什么需要重新定义EXIT\u ON\u CLOSE?不,我没有重新定义它。我觉得没必要。但正如源代码所示,它是在JFrame中定义的。我只是想知道为什么。因为在API中有默认的HIDE_ON_CLOSE,它与EXIT_ON_CLOSE没有任何关系:-)在Java5/6(最新5和新6版本)中/从Java5/6更改@mKorbel我看到有一个
private int defaultCloseOperation=HIDE_ON_CLOSE
JFrame
中。但是我仍然不明白为什么在
JFrame
中对
EXIT\u ON\u CLOSE
进行了重新定义。谢谢!为了便于其他人参考,我将Java 1.3的日语链接粘贴到这里: