import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/**<applet code=”CheckboxDemo.class” width=500 height=500>
</applet>
*/
public class CheckboxDemo extends Applet implements ItemListener
{
Color color;
Font f;
Checkbox fc1;
Checkbox fc2;
Checkbox fc3;
Checkbox fs1;
Checkbox fs2;
Checkbox fs3;
Checkbox fst1;
Checkbox fst2;
Checkbox fst3;
Checkbox cb1;
Checkbox cb2;
Checkbox cb3;
CheckboxGroup c1;
CheckboxGroup c2;
CheckboxGroup c3;
Object o;
public void init()
{
c1=new CheckboxGroup();
c2=new CheckboxGroup();
c3=new CheckboxGroup();
cb1=new Checkbox(“c1”,null,false);
cb2=new Checkbox(“c2”,null,false);
cb3=new Checkbox(“c3”,null,true);
fc1=new Checkbox(“RED”,c1,false);
fc2=new Checkbox(“GREEN”,c1,false);
fc3=new Checkbox(“BLUE”,c1,false);
fs1=new Checkbox(“15”,c2,false);
fs2=new Checkbox(“25”,c2,false);
fs3=new Checkbox(“35”,c2,false);
fst1=new Checkbox(“BOLD”,c3,false);
fst2=new Checkbox(“ITALIC”,c3,false);
fst3=new Checkbox(“PLAIN”,c3,false);
fc1.addItemListener(this);
fc2.addItemListener(this);
fc3.addItemListener(this);
fst1.addItemListener(this);
fst2.addItemListener(this);
fst3.addItemListener(this);
fs1.addItemListener(this);
fs2.addItemListener(this);
fs3.addItemListener(this);
cb1.addItemListener(this);
cb2.addItemListener(this);
cb3.addItemListener(this);
add(fc1);
add(fc2);
add(fc3);
add(fs1);
add(fs2);
add(fs3);
add(fst1);
add(fst2);
add(fst3);
add(cb1);
add(cb2);
add(cb3);
}
public void itemStateChanged(ItemEvent e)
{
o=e.getItemSelectable();
if(o==fc1)
{
color=Color.red;
repaint();
}
if(o==fc2)
{
color=Color.green;
repaint();
}
if(o==fc3)
{
color=Color.blue;
repaint();
}
if(o==fs1)
{
f=new Font(“TimesNewRoman”,Font.BOLD,15);
repaint();
}
if(o==fs2)
{
f=new Font(“TimesNewRoman”,Font.BOLD,25);
repaint();
}
if(o==fs3)
{
f=new Font(“TimesNewRoman”,Font.BOLD,35);
repaint();
}
if(o==fst1)
{
f=new Font(“TimesNewRoman”,Font.BOLD,15);
repaint();
}
if(o==fst2)
{
f=new Font(“TimesNewRoman”,Font.ITALIC,25);
repaint();
}
if(o==fst3)
{
f=new Font(“TimesNewRoman”,Font.PLAIN,35);
repaint();
}
if(o==cb1)
{
repaint();
}
if(o==cb2)
{
repaint();
}
if(o==cb3)
{
repaint();
}
}
public void paint(Graphics g)
{
g.setFont(f);
g.setColor(color);
g.drawString(“WELCOME TO APPLET”,0,200);
g.drawString(“Chechbox1 state”+cb1.getState(),0,300);
g.drawString(“Chechbox2 state”+cb2.getState(),0,380);
g.drawString(“Chechbox3 state”+cb3.getState(),0,450);
}
}
No comments:
Post a Comment