Java Reference
In-Depth Information
30
leftJButton.addActionListener(
31
new
ActionListener()
// anonymous inner class
32
{
33
// process leftJButton event
34
@Override
35
public
void
actionPerformed(ActionEvent event)
36
{
37
layout.setAlignment(
FlowLayout.LEFT
);
38
39
// realign attached components
40
layout.layoutContainer(container);
41
}
42
}
43
);
44
45
// set up centerJButton and register listener
46
centerJButton =
new
JButton(
"Center"
);
47
add(centerJButton);
// add Center button to frame
48
centerJButton.addActionListener(
49
new
ActionListener()
// anonymous inner class
50
{
51
// process centerJButton event
52
@Override
53
public
void
actionPerformed(ActionEvent event)
54
{
55
layout.setAlignment(
FlowLayout.CENTER
);
56
57
// realign attached components
58
layout.layoutContainer(container);
59
}
60
}
61
);
62
63
// set up rightJButton and register listener
64
rightJButton =
new
JButton(
"Right"
);
65
add(rightJButton);
// add Right button to frame
66
rightJButton.addActionListener(
67
new
ActionListener()
// anonymous inner class
68
{
69
// process rightJButton event
70
@Override
71
public
void
actionPerformed(ActionEvent event)
72
{
73
layout.setAlignment(
FlowLayout.RIGHT
);
74
75
// realign attached components
76
layout.layoutContainer(container);
77
}
78
}
79
);
80
}
// end FlowLayoutFrame constructor
81
}
// end class FlowLayoutFrame
Fig. 12.39
|
FlowLayout
allows components to flow over multiple lines. (Part 2 of 2.)