Java Reference
In-Depth Information
LISTING 11.9
continued
public
LightBulbPanel()
{
lightOn =
new
ImageIcon ("lightBulbOn.gif");
lightOff =
new
ImageIcon ("lightBulbOff.gif");
setBackground (Color.black);
on =
true
;
imageLabel =
new
JLabel (lightOff);
add (imageLabel);
}
//-----------------------------------------------------------------
// Paints the panel using the appropriate image.
//-----------------------------------------------------------------
public void
paintComponent (Graphics page)
{
super
.paintComponent(page);
if
(on)
imageLabel.setIcon (lightOn);
else
imageLabel.setIcon (lightOff);
}
//-----------------------------------------------------------------
// Sets the status of the light bulb.
//-----------------------------------------------------------------
public void
setOn (
boolean
lightBulbOn)
{
on = lightBulbOn;
}
}
The
LightBulbControls
class shown in Listing 11.10 is a panel that contains
the on and off buttons. Both of these buttons have tool tips assigned to them,
and both use mnemonics. Also, when one of the buttons is enabled, the other is
disabled, and vice versa. When the light bulb is on, there is no reason for the
On
button to be enabled. Likewise, when the light bulb is off, there is no reason for
the
Off
button to be enabled.
VideoNote
Exploring GUI
design details.
Search WWH ::
Custom Search