Java Reference
In-Depth Information
LISTING 5.17
continued
if (source == comedy)
quote.setText (comedyQuote);
else
if (source == philosophy)
quote.setText (philosophyQuote);
else
quote.setText (carpentryQuote);
}
}
}
Note that unlike push buttons, both check boxes and radio buttons are toggle
buttons, meaning that at any time they are either on or off. The difference is in
how they are used. Independent options (choose any combination) are controlled
with check boxes. Dependent options (choose one of a set) are controlled with
radio buttons. If there is only one option to be managed, a check box can be used
by itself. As we mentioned earlier, a radio button, on the other hand, makes sense
only in conjunction with one or more other radio buttons.
Also note that check boxes and radio buttons produce different types of events.
A check box produces an item event, and a radio button produces an action event.
The use of different event types is related to the differences in button function-
ality. A check box produces an event when it is selected or deselected, and the
listener could make the distinction if desired. A radio button, on the other hand,
produces an event only when it is selected (the currently selected button from the
group is deselected automatically).
 
Search WWH ::




Custom Search