Java Reference
In-Depth Information
You have specified the top-left corner of the application window at position (50,100) on the screen, which
is 50 pixels to the right and 100 pixels down. Because the window is 400 pixels wide and 150 pixels high,
the bottom-right corner is at position (450,250). The actual physical width and height of the window, as
well as its position relative to the edge of the screen, depends on the size of your screen and the display
resolution. For a given screen size, the higher the display resolution, the smaller the window is and the
closer it is to the top left-hand corner, simply because the pixels on the screen are closer together. You
see how you can get around this potential problem later in this chapter.
Window Close Options
The setDefaultCloseOperation() method for the JFrame object determines what happens when you
close the window by either clicking on the X icon or selecting Close from the menu that is displayed
when you click the Java icon in the top-left corner of the window. There are four possible argument val-
ues you can use here. The constant you have used as the argument to the method is EXIT_ON_CLOSE ,
which is defined in the JFrame class. The effect of this is to close the window, dispose of the window re-
sources and those of any components it contains, and finally to terminate the application. There are three
other argument values you could use with the setDefaultCloseOperation() method that are defined
in the WindowConstants interface that is implemented by the JFrame class. These values are shown in
Table 17-1 :
TABLE 17-1 : Argument Values for setDefaultCloseOperation()
ARGUMENT DESCRIPTION
DISPOSE_ON_CLOSE This causes the frame and any components it contains to be destroyed but doesn't
terminate the application.
DO_NOTHING_ON_CLOSE This makes the close operation for the frame window ineffective.
HIDE_ON_CLOSE
This just hides the window by calling its setVisible() method with an argument of
false . This is the default action if you don't call the setDefaultCloseOpera-
tion() method with a different argument value. When a window is hidden, you can
 
 
Search WWH ::




Custom Search