
m 8.2 Swing Components
1 ! 3
individual button objects to be of type JRadioButton. Then declare the radio button group
object to be of type ButtonGroup. For example,
JRadioButton agel, age2, age3,
age4;
ButtonGroup ageButton;
Then invoke the javax, swing.ButtonGroup constructor, as follows:
ageButton = new ButtonGroup();
The individual buttons are created using the javax, swing.JRadioButton constructor, for ex-
ample
agel = new JRadioButton("age under 20") ;
The individual buttons are then added to the radio button group using the j avax. swing.Button-
Group. add method, as follows:
ageButton.add(agel);
8.2.5 ...