Checkbox Group:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*<applet code="CheckGroup" width=300 height=300></applet>*/
public class CheckGroup extends Applet implements ItemListener
{
Label l1;
public void init()
{
CheckboxGroup cbg=new CheckboxGroup();
Checkbox c1=new Checkbox("Male",cbg,true);
c1.addItemListener(this);
add(c1);
Checkbox c2=new Checkbox("Female",cbg,false);
c2.addItemListener(this);
add(c2);
l1=new Label(" ");
add(l1);
}
public void itemStateChanged(ItemEvent ie)
{
Checkbox cb=(Checkbox)ie.getItemSelectable();
l1.setText(cb.getLabel());
}
}
Comments
Post a Comment