Why JFrame redefine the “EXIT_ON_CLOSE” which it inherits from interface “WindowConstants”?

后端 未结 1 1429
野性不改
野性不改 2021-01-03 09:16

WindowConstants is defined as this:

public interface WindowConstants
{
    public static final int DO_NOTHING_ON_CLOSE = 0;

    public static f         


        
相关标签:
1条回答
  • 2021-01-03 09:27

    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)

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

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

    0 讨论(0)
提交回复
热议问题