/* The program demonstrate the use of JRadioButton * */ import javax.swing.*; public class RadioButton extends JFrame { JRadioButton pepsi, coke, tea; JPanel panel = new JPanel(); public RadioButton() { // Sets the title setTitle("Radio Button"); // Sets the window size setSize(300, 400); // Sets the action when the window close setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create a button group to group the radio buttons together ButtonGroup group = new ButtonGroup(); // Creates a radio button for pepsi pepsi = new JRadioButton("Pepsi"); // Creates a radio button for coke coke = new JRadioButton("Coke"); // Creates a radio button for Tea tea = new JRadioButton("Tea"); // Add the radio button to the group group.add(pepsi); group.add(coke); group.add(tea); // Adds the button to the panel panel.add(pepsi); panel.add(coke); panel.add(tea); // Adds the panel to the content pane add(panel); // Sets the window to be visible setVisible(true); } public static void main(String[] args) { new RadioButton(); } }