Java Reference
In-Depth Information
LISTING 11.10
continued
//--------------------------------------------------------------
// Turns the bulb on and repaints the bulb panel.
//--------------------------------------------------------------
public void
actionPerformed (ActionEvent event)
{
bulb.setOn (
true
);
onButton.setEnabled (
false
);
offButton.setEnabled (
true
);
bulb.repaint();
}
}
//*****************************************************************
// Represents the listener for the Off button.
//*****************************************************************
private class
OffListener
implements
ActionListener
{
//--------------------------------------------------------------
// Turns the bulb off and repaints the bulb panel.
//--------------------------------------------------------------
public void
actionPerformed (ActionEvent event)
{
bulb.setOn (
false
);
onButton.setEnabled (
true
);
offButton.setEnabled (
false
);
bulb.repaint();
}
}
}
Each button has its own listener class. The
actionPerformed
method of each
sets the bulb's status, toggles the enabled state of both buttons, and causes the
panel with the image to repaint itself.
Note that the mnemonic characters used for each button are underlined in the
display. When you run the program, note that the tool tips automatically include
an indication of the mnemonic that can be used for the button.
SELF-REVIEW QUESTIONS
(see answers in Appendix N)
SR 11.19
What is a tool tip?
SR 11.20
What is a mnemonic and how is it used?
SR 11.21
Why might you want to disable a component?
Search WWH ::
Custom Search