Java Reference
In-Depth Information
1
// Fig. 12.16: ButtonTest.java
2
// Testing ButtonFrame.
3
import
javax.swing.JFrame;
4
5
public
class
ButtonTest
6
{
7
public
static
void
main(String[] args)
8
{
9
ButtonFrame buttonFrame =
new
ButtonFrame();
10
buttonFrame.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE
);
11
buttonFrame.setSize(
275
,
110
);
12
buttonFrame.setVisible(
true
);
13
}
14
}
// end class ButtonTest
Fig. 12.16
|
Testing
ButtonFrame
.
Lines 14-15 declare
JButton
variables
plainJButton
and
fancyJButton
. The corre-
sponding objects are instantiated in the constructor. Line 23 creates
plainJButton
with
the button label
"Plain
Button"
. Line 24 adds the
JButton
to the
JFrame
.
A
JButton
can display an
Icon
. To provide the user with an extra level of visual inter-
action with the GUI, a
JButton
can also have a
rollover
Icon
—an
Icon
that's displayed
when the user positions the mouse over the
JButton
. The icon on the
JButton
changes as
the mouse moves in and out of the
JButton
's area on the screen. Lines 26-27 create two