//Java ItemListener
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class JCheckBox extends Applet implements ItemListener
{
String msg="";
Checkbox winXP,winVista,Solaris,Mac;
public void init()
{
winXP=new Checkbox("Windows XP");
winVista=new Checkbox("Windows Vista");
Solaris=new Checkbox("Solaris");
Mac=new Checkbox("Mac");
add(winXP);
add(winVista);
add(Solaris);
add(Mac);
winXP.addItemListener(this);
winVista.addItemListener(this);
Solaris.addItemListener(this);
Mac.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
repaint();
}
public void paint(Graphics g)
{
msg="Current State :: ";
g.drawString(msg,6,80);
msg="Windows XP :: "+winXP.getState();
g.drawString(msg,6,100);
msg="Windows Vista :: "+winVista.getState();
g.drawString(msg,6,120);
msg="Solaris :: "+Solaris.getState();
g.drawString(msg,6,140);
msg="Mac :: "+Mac.getState();
g.drawString(msg,6,160);
}
}
Comments
Post a Comment