WindowConstants
is defined as this:
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
is defined as this:
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;
Why the EXIT_ON_CLOSE
is redefined? And since it is final
in the WindowConstants
interface, how could it be redefined?
In Java 1.3, when this was all added,
EXIT_ON_CLOSE
was relevant only toJFrame
and not to other implementations ofWindowConstants
. As such - it was not present inWindowConstants
and was defined inJFrame
. The 3 otherXXX_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 fromJFrame
due to compatibility issues.There is no redefining there. What's happening is shadowing. I.e. the
JFrame
field hides (but does not eliminate) theWindowConstants
field.