JRadioButton and Button Group Example Java

JRadioButton and Button Group Example Java


This is an exclusive program on JRadioButton and ButtonGroup.

To group six radio buttons, two objects of ButtonGroup are created and for each group three radio buttons are added. User’s selection is displayed using JOptionPane showMessageDialog() method. There is no counterpart class for this class in java.awt package; it is a new introduction in javax.swing package. The counterpart of ButtonGroup in AWT is CheckboxGroup.

Example on JRadioButton – ButtonGroup

JRadioButton

String name = “”, color = “”;

Two temporary string variables, name and color are taken and values are assigned dynamically as per the user selection of radio buttons. These values are displayed in JOptionPane.

Two more programs exist on JCheckBox and JRadioButton:

1. JCheckBox and JRadioButton
2. JCheckBox Selection

Leave a Reply

Your email address will not be published. Required fields are marked *