Am not able handle the events of checkboxgroup which act as radio button in applet.. i wanto display a message on applet whenever the checkbox is selected but its not working.. i wanto show a checkbox state with its label in applet,whenever any checkbox is selected then it seems to be display the label and state of checkbox...also the state of the checkbox is not changing... when i click on the checkbox c2 i.e "No" then the state of the checkbox is not changing...
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code="chg.class" height=500 width=600></applet>*/
public class chg extends Applet implements ItemListener
{
String msg="Current Selection is:";
Checkbox c1,c2,c3,c4,c5;
CheckboxGroup cbg;
public void init()
{
cbg=new CheckboxGroup();
c1=new Checkbox("YES",cbg,true);
c2=new Checkbox("No",cbg,false);
c3=new Checkbox("can",cbg,false);
c4=new Checkbox("cant",cbg,false);
c5=new Checkbox("ok",cbg,false);
add(c1);
add(c2);
add(c3);
add(c4);
add(c5);
}
public void itemStateChanged(ItemEvent ie)
{
if(ie.getSource()==c2)
{
cbg.setSelectedCheckbox(c2);
}
else if(ie.getSource()==c3)
{
cbg.setSelectedCheckbox(c3);
}
else if(ie.getSource()==c4)
{
cbg.setSelectedCheckbox(c4);
}
else
{
cbg.setSelectedCheckbox(c5);
}
repaint();
}
public void paint(Graphics g)
{
msg+=cbg.getSelectedCheckbox().getLabel();
g.drawString(msg,6,130);
}
}