gpt4 book ai didi

java - 为什么 JFrame 重新定义它从接口(interface) "EXIT_ON_CLOSE"继承的 "WindowConstants"?

转载 作者:搜寻专家 更新时间:2023-11-01 01:51:43 24 4
gpt4 key购买 nike

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接口(interface)中的final,怎么可能重新定义呢?

最佳答案

在 Java 1.3 中,当这一切都被添加时,EXIT_ON_CLOSE 仅与 JFrame 相关,与 WindowConstants 的其他实现无关。因此 - 它出现在 WindowConstants 中,并在 JFrame 中定义。其他 3 个 XXX_ON_CLOSE 选项在界面中。 (英语 Javadoc 不再在线,但仍然可以下载,所以这里没有引用。如果您搜索“WindowConstants Java 1.3”,您将获得日语版本的 Javadoc - 但由于页面结构相同,您仍然可以看到重点)

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

那里没有重新定义。发生的事情是 shadowing . IE。 JFrame 字段隐藏(但不消除)WindowConstants 字段。

关于java - 为什么 JFrame 重新定义它从接口(interface) "EXIT_ON_CLOSE"继承的 "WindowConstants"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27358261/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com