Java Reference
In-Depth Information
LISTING 11.10
//********************************************************************
// LightBulbControls.java Author: Lewis/Loftus
//
// Represents the control panel for the LightBulb program.
//********************************************************************
import
javax.swing.*;
import
java.awt.*;
import
java.awt.event.*;
public class
LightBulbControls
extends
JPanel
{
private
LightBulbPanel bulb;
private
JButton onButton, offButton;
//-----------------------------------------------------------------
// Sets up the lightbulb control panel.
//-----------------------------------------------------------------
public
LightBulbControls (LightBulbPanel bulbPanel)
{
bulb = bulbPanel;
onButton =
new
JButton ("On");
onButton.setEnabled (
false
);
onButton.setMnemonic ('n');
onButton.setToolTipText ("Turn it on!");
onButton.addActionListener (
new
OnListener());
offButton =
new
JButton ("Off");
offButton.setEnabled (
true
);
offButton.setMnemonic ('f');
offButton.setToolTipText ("Turn it off!");
offButton.addActionListener (
new
OffListener());
setBackground (Color.black);
add (onButton);
add (offButton);
}
//*****************************************************************
// Represents the listener for the On button.
//*****************************************************************
private class
OnListener
implements
ActionListener
{
Search WWH ::
Custom Search