为什么JFrame重新定义"EXIT_ON_CLOSE"它是从接口"WindowConstants"继承的? [英] Why JFrame redefine the "EXIT_ON_CLOSE" which it inherits from interface "WindowConstants"?

查看:217
本文介绍了为什么JFrame重新定义"EXIT_ON_CLOSE"它是从接口"WindowConstants"继承的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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,如何重新定义它?

Why the EXIT_ON_CLOSE is redefined? And since it is final in the WindowConstants interface, how could it be redefined?

推荐答案

在Java 1.3中,当全部添加时,EXIT_ON_CLOSE仅与JFrame相关,而与WindowConstants的其他实现无关.这样-它在WindowConstants中不存在 并在JFrame中定义.界面中还有其他3个XXX_ON_CLOSE选项. (英语Javadoc不再在线,尽管仍然可以下载,所以这里没有参考.如果您搜索"WindowConstants Java 1.3",则会获得日语版的Javadoc-但由于页面结构相同,因此您仍然可以看到重点)

In Java 1.3, when this was all added, EXIT_ON_CLOSE was relevant only to JFrame and not to other implementations of WindowConstants. As such - it was not present in WindowConstants and was defined in JFrame. The 3 other XXX_ON_CLOSE options were in the interface. (English Javadoc is not online anymore, though still downloadable, so no reference here. If you search for "WindowConstants Java 1.3" you'll get a Japanese version of the Javadoc - but since the page structure is the same, you can still see the point)

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

It was later (1.4) moved to WindowConstants, however the field was not removed from JFrame due to compatibility issues.

这里没有重新定义.发生了什么事阴影. IE. JFrame字段隐藏(但不消除)WindowConstants字段.

There is no redefining there. What's happening is shadowing. I.e. the JFrame field hides (but does not eliminate) the WindowConstants field.

这篇关于为什么JFrame重新定义"EXIT_ON_CLOSE"它是从接口"WindowConstants"继承的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆