Why JFrame redefine the quot;EXIT_ON_CLOSEquot; which it inherits from interface quot;WindowConstantsquot;?(为什么 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"继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 JFrame 重新定义了“EXIT_ON_CLOSE"?它从接口“WindowConstants"继承?
基础教程推荐
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 大摇大摆的枚举 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 从 python 访问 JVM 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
