Java Reference
In-Depth Information
Sample Run: Figure 12-19 shows a sample run of the
FlowLayoutExample
program.
FIGURE 12-19
Sample run of the
FlowLayoutExample
program
The preceding program works as follows: The statement in Line 1 sets the title of the
window. The statement in Line 2 accesses the content pane. The statement in Line 3
sets the size of the window. The statement in Line 4 creates the
FlowLayout
object
flowLayoutMgr
; the statement in Line 5 uses this object to set the layout of the pane
to
FlowLayout
.(Becausewedidnotspecifythelayout,thedefaultlayout,
CENTERED
,
is assumed.) The statement in Line 6 instantiates the
JLabel
object
labelJL
.
The statement in Line 7 instantiates the
JTextField
object
textFieldTF
,andthe
statement in Line 8 sets the text of the object
textFieldTF
. The statement in Line 9
instantiates the
JButton
object
buttonJB
. The statement in Line 10 instantiates
the
JCheckBox
object
checkboxCB
. The statement in Line 11 instantiates the
JRadioButton
object
radioButtonRB
. The statement in Line 12 instantiates the
JTextArea
object
textAreaTA
with 10 rows and 20 columns. The statement in
Line 13 places the text
Sixth Component
into the text area. The statement in Line 14
appends the text:
Use the mouse to resize the window.
The statements in Lines 15 through 20 place the GUI components in the pane. The
statement in Line 21 sets the visibility of the window to
true
, and the statement in Line
22 sets the window closing option to close when the program terminates. When the
program executes, the statement in Line 24 creates the window with the GUI compo-
nents shown in the sample run.
Search WWH ::
Custom Search