8.1 Frames | 377
frame
Content
pane
Figure 8.1 A Frame and Its Content Pane
Instantiate Frame Objects and Specify Some of Their Properties
The second step in using a frame has five parts.
1.Instantiate a JFrameobject.
2.Ask the JFrameobject to return a content pane object whose address we assign to
the Containervariable.
3.Specify the action to take when the window is closed.
4.Specify the size of the JFrameobject (adjust its size to fit the output).
5.Specify a layout manager for the content pane object.
So far, we have imported the JFrameclass and declared a variable of the class JFrame. Like
any other variable, the variable called outputFrameremains empty until we assign it a value.
What sort of value do we assign to a JFramevariable? The answer to this question is both triv-
ial and deep: We assign it the address of a JFrameobject. The answer is trivial because it
seems so obvious, like the answer to the question, “Who is buried in Grant’s tomb?” In prac-
tice, it is really that simple. We just write the following assignment statement:
outputFrame = new JFrame();
Java then instantiates an object of the class JFrameand assigns its address to outputFrame. The
answer to our question is deep because the actual contents of a JFrameobject are quite com-
plex. We could read a biography of President Grant as one way of knowing who is buried in