// RadioButton swing
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class radioButton extends JFrame implements ActionListener
{
JFrame f;
JRadioButton b1,b2;
public radioButton()
{
f=new JFrame("RadioButton Example");
b1=new JRadioButton("Male",new ImageIcon("D:/male.png"));
b1.addActionListener(this);
b2=new JRadioButton("Female",new ImageIcon("D:/female.png"));
b2.addActionListener(this);
ButtonGroup bg=new ButtonGroup();
bg.add(b1);
bg.add(b2);
f.add(b1);
f.add(b2);
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
f.setLayout(new FlowLayout());
f.setSize(400,400);
f.setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if(b1.isSelected())
{
JOptionPane.showMessageDialog(null,"Male");
}
if(b2.isSelected())
{
JOptionPane.showMessageDialog(null,"Female");
}
}
public static void main(String args[])
{
new radioButton();
}
}