*Java source
import java.applet.Applet;
import java.awt.*;

public class test6 extends Applet{
int oldx, oldy;
Graphics g;

public void init(){
g=getGraphics();
CheckboxGroup cg=new CheckboxGroup();
setBackground(Color.blue);
add(new Checkbox("blue",cg,false));
setBackground(Color.green);
add(new Checkbox("green",cg,false));
setBackground(Color.red);
add(new Checkbox("red",cg,false));
setBackground(Color.pink);
add(new Checkbox("pink",cg,false));
setBackground(Color.yellow);
add(new Checkbox("yellow",cg,false));
setBackground(Color.orange);
add(new Checkbox("orange",cg,false));
setBackground(Color.lightGray);
add(new Checkbox("black",cg,true));
setBackground(Color.white);
}

public boolean mouseDown(Event e,int x,int y){
oldx=x; oldy=y;
return true;
}

public boolean mouseDrag(Event e,int x,int y){
g.drawLine(oldx,oldy,x,y);
oldx=x; oldy=y;
return true;
}

public boolean action(Event e,Object o){
Checkbox c=(Checkbox)e.target;
if ("blue".equals(c.getLabel()))
g.setColor(Color.blue);
else if ("green".equals(c.getLabel()))
g.setColor(Color.green);
else if ("red".equals(c.getLabel())) g.setColor(Color.red);
else if ("pink".equals(c.getLabel()))
g.setColor(Color.pink);
else if ("yellow".equals(c.getLabel()))
g.setColor(Color.yellow);
else if ("orange".equals(c.getLabel()))
g.setColor(Color.orange);
else
g.setColor(Color.black);
return true;
}
}



Back