
Forgetting to make
JRadioButtons part of the
same ButtonGroup makes
them independent and not
mutually exclusive.
COMMON ERROR
TRAP
12.7 Radio Buttons and Checkboxes 853
Figure 12.8
Running Example 12.5
red radio button will be selected. In order to reflect the effect of the selected
radio button, we set the background color of the label to red at line 30.
At lines 24 and 25, green and blue are instantiated using the JRadioButton
constructor with only a String argument, specifying the radio button titles.
The four components are added to the content pane at lines 32–35.
At lines 37–41, we instantiate a ButtonGroup object, then add the red, green,
and blue