Java Reference
In-Depth Information
5
public
class
LookAndFeelDemo
6
{
7
public
static
void
main(String[] args)
8
{
9
LookAndFeelFrame lookAndFeelFrame =
new
LookAndFeelFrame();
10
lookAndFeelFrame.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE
);
11
lookAndFeelFrame.setSize(
400
,
220
);
12
lookAndFeelFrame.setVisible(
true
);
13
}
14
}
// end class LookAndFeelDemo
Fig. 22.10
|
Test class for
LookAndFeelFrame
. (Part 2 of 2.)
Our utility method
changeTheLookAndFeel
(lines 81-95) is called by the event handler
for the
JRadioButton
s at the bottom of the user interface. The event handler (declared in
private
inner class
ItemHandler
at lines 98-115) passes an integer representing the element
in array
looks
that should be used to change the look-and-feel. Line 86 invokes
static
method
setLookAndFeel
of
UIManager
to change the look-and-feel. The
getClassName
method of class
UIManager.LookAndFeelInfo
determines the name of the look-and-feel
class that corresponds to the
UIManager.LookAndFeelInfo
object. If the look-and-feel is not
already loaded, it will be loaded as part of the call to
setLookAndFeel
. Line 89 invokes the
static
method
updateComponentTreeUI
of class
SwingUtilities
(package
javax.swing
)
to change the look-and-feel of every GUI component attached to its argument (
this
instance of our application class
LookAndFeelFrame
) to the new look-and-feel.