import java.applet.*;
import java.awt.event.*;
import java.awt.*;
public class CheckboxDemo extends Applet implements ItemListener{
String msg="";
Checkbox WindowXP,MacOS,Solaris,Linux;
public void init()
{
WindowXP=new Checkbox("Window XP");
MacOS=new Checkbox("MacOS");
Solaris=new Checkbox("Solaris");
Linux=new Checkbox("Linux");
add(WindowXP);
add(MacOS);
add(Solaris);
add(Linux);
WindowXP.addItemListener(this);
MacOS.addItemListener(this);
Solaris.addItemListener(this);
Linux.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
repaint();
}
//Display Current State of the Checkbox
public void paint(Graphics g)
{
msg="Current State:";
g.drawString(msg, 6, 80);
msg="Window XP :"+WindowXP.getState();
g.drawString(msg,6,100);
msg="Mac OS : "+MacOS.getState();
g.drawString(msg,6,120);
msg="Linux : "+Solaris.getState();
g.drawString(msg,6,140);
msg="Linux : "+Linux.getState();
g.drawString(msg, 6, 160);
}
}
import java.awt.event.*;
import java.awt.*;
public class CheckboxDemo extends Applet implements ItemListener{
String msg="";
Checkbox WindowXP,MacOS,Solaris,Linux;
public void init()
{
WindowXP=new Checkbox("Window XP");
MacOS=new Checkbox("MacOS");
Solaris=new Checkbox("Solaris");
Linux=new Checkbox("Linux");
add(WindowXP);
add(MacOS);
add(Solaris);
add(Linux);
WindowXP.addItemListener(this);
MacOS.addItemListener(this);
Solaris.addItemListener(this);
Linux.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
repaint();
}
//Display Current State of the Checkbox
public void paint(Graphics g)
{
msg="Current State:";
g.drawString(msg, 6, 80);
msg="Window XP :"+WindowXP.getState();
g.drawString(msg,6,100);
msg="Mac OS : "+MacOS.getState();
g.drawString(msg,6,120);
msg="Linux : "+Solaris.getState();
g.drawString(msg,6,140);
msg="Linux : "+Linux.getState();
g.drawString(msg, 6, 160);
}
}
No comments:
Post a Comment