It is one of the few ``non-painted'' graphics components.
Frames are examples of containers and we will study ways of inserting graphics objects into them.
The 'x' stands for 'extension'.
By default JFrame has 0x0 pixels! You need to
define your own frame class which extends it and which is bigger. Use the
setSize() method to increase its size.
Units of size are pixels.
defines what happens when you close the frame
In other programs you would want to change this so that the program did not exit whenever the user closed a window. By default a frame is ``hidden'' when a user closes it but the program does not terminate.
Frames start their life invisible! You must call show
to display them.
Note that the main program exits after the show call.
This just terminates the main thread.
Graphics is in a separate thread.
Many of the useful JFrame methods are inherited from other classes further up the hierarchy
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--java.awt.Window | +--java.awt.Frame | +--javax.swing.JFrame
setLocation(x,y)
This method can move the frame around. Note that y measures the number of pixels down from the top left corner of the screen. Also note that both arguments are integers.
Note that the coordinates in JFrame methods
are with respect to the whole screen. In other swing classes they are usually
with respect to a specific container.
It is possible to get the dimensions of the screen you are using by creating an object of class Toolkit and calling its getScreenSize() method. This returns the width and height as fields in a dimension object. The pattern is
Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int screenHeight = screenSize.height; int screenWidth = screenSize.width;