java.awt.CheckboxGroup
CheckboxGroup
are often called radio buttons. Checkboxes that are members of the same CheckboxGroup
cannot be checked simultaneously. When the user checks one, all others are unchecked automatically.
The constructor for a CheckboxGroup
is trivial. No arguments are needed. You do not even need to add the CheckboxGroup
to the applet since checkbox groups are themselves not user-interface widgets, just ways of arranging checkboxes.
CheckboxGroup cbg = new CheckboxGroup();
To make check boxes act like radio buttons, use this constructor
Checkbox(String label, CheckboxGroup cbg, boolean checked)
for each Checkbox
in the group. The label is the label for this Checkbox
. The CheckboxGroup
is the group you want this Checkbox
to belong to and must already exist.
At any time, you can get or set the selected Checkbox
with these two methods:
public Checkbox getSelectedCheckbox()
public synchronized void setSelectedCheckbox(Checkbox box)