Saturday 28 June 2014

Program to show the example of radio buttons

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
public class Radio extends Applet implements ActionListener
{
Checkbox ch1,ch2;
CheckboxGroup cbg;
Button b1;

public void init()
{
cbg=new CheckboxGroup();
b1=new Button("check");
ch1= new Checkbox("male",cbg,true);
ch2= new Checkbox("female", cbg,true);
add(ch1);
add(ch2);
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
String a=" ", b=" ", c=" ";
if(e.getSource()==b1)
{
if(ch1.getState()==true)
{a="male";}
else if(ch2.getState()==true)
{b="female";}

JOptionPane.showMessageDialog(this, "u have selected "+a+b);

}
}}

output:


No comments:

Post a Comment

SAY HELLO!!