Java Reference
In-Depth Information
Figure 13.5 Swing check boxes have a different look and feel from AWT check boxes, but
their functionality is the same.
Radio Buttons
A radio button is a component that is either selected or deselected, similar to a
check box. The difference with radio buttons is that they are associated with a
group, and only one radio button in the group can be selected. When a radio
button in the group is selected, any other previously selected one in the group
is deselected.
It takes two classes to create a group of radio buttons: one for the radio but-
ton component, and one for the group. Let's discuss how to create them for
both AWT and Swing.
AWT Radio Buttons
When using AWT, the java.awt.Checkbox and java.awt.CheckboxGroup
classes are used to create a group of radio buttons. You start by creating a
CheckboxGroup object using its only constructor:
public CheckboxGroup().
Creates a new CheckboxGroup object.
The following methods in the CheckboxGroup class are used to set or deter-
mine which radio button in the group is selected:
public void setSelectedCheckbox(Checkbox c). Sets the given check
box as the currently selected radio button in the group. Passing in null
deselects all check boxes.
Search WWH ::




Custom Search