import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class RadioButtonSample extends JFrame implements ActionListener
{
private static final int boxW = 800;
private static final int boxH = 450;
private static final int box_X_o = 180;
private static final int box_Y_o = 200;
private JLabel label;
private JRadioButton first;
private JRadioButton second;
private JRadioButton third;
private JRadioButton fourth;
private JRadioButton fifth;
private JButton oKButton;
public RadioButtonSample()
{
setTitle ("Button Sample");
setSize (boxW ,boxH);
setLocation (box_X_o , box_Y_o);
// Container contentPane = getContentPane();
// contentPane.setBackground(Color.white);
// contentPane.setLayout(null);
oKButton = new JButton("Ok");
// oKButton.setBounds(610, 375, 80, 30);
// contentPane.add(oKButton);
// oKButton.addActionListener(this);
first = new JRadioButton("First");
second = new JRadioButton("Second");
third = new JRadioButton("Third");
fourth = new JRadioButton("Fourth");
fifth = new JRadioButton("Fifth");
JPanel panel = new JPanel();
panel.add(first);
panel.add(second);
panel.add(third);
panel.add(fourth);
panel.add(fifth);
panel.add(oKButton);
ButtonGroup bg = new ButtonGroup();
bg.add(first);
bg.add(second);
bg.add(third);
bg.add(fourth);
bg.add(fifth);
bg.add(oKButton);
first.addActionListener(this);
second.addActionListener(this);
third.addActionListener(this);
fourth.addActionListener(this);
fifth.addActionListener(this);
oKButton.addActionListener(this);
label = new JLabel("Roseindia.net");
getContentPane().add(panel, BorderLayout.NORTH);
getContentPane().add(label, BorderLayout.CENTER);
getContentPane().setSize(400, 400);
getContentPane().setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
label.setText(e.getActionCommand());
JOptionPane.showMessageDialog(null, "This is the " + e.getActionCommand() + " radio button.");
}
public static void main(String[] args)
{
RadioButtonSample sr = new RadioButtonSample();
sr.setVisible(true);
}
}