
import java.awt.*;


public class test extends java.applet.Applet {

int move = 0;
ball b,r,g;

	public void init(){
		setLayout(null);
		b = new ball(Color.blue);
		add(b);
		b.reshape(70,70,10,10);
		r = new ball();
	        add(r);
		r.reshape(50,50,10,10);
		g = new ball(Color.green,"this is green");
		add(g);
		g.reshape(50,50,50,10);
		TextArea ta = new TextArea("Fooo");
		ta.reshape(0,100,200,50);
		add(ta);
	}

	public boolean handleEvent(Event e){
		if(e.id == Event.MOUSE_DRAG){
		          if(move==1) (r).move(e.x,e.y);
		     else if(move==2) (g).move(e.x,e.y);
		     else if(move==3) (b).move(e.x,e.y);
		}
		else if(e.id == Event.MOUSE_DOWN){
			if(e.target instanceof ball){
				if((ball)e.target == r)
					move = 1;
				else if((ball)e.target == g)
					move = 2;
				else if((ball)e.target == b)
					move = 3;
				else move = 0;
			}
		}
		else if(e.id == Event.MOUSE_UP){
			move = 0;
		}
			//System.out.println(e);
		return true;
	}

}

class ball extends Canvas {
 Color c = Color.red;
 String lbl = "";
 
    public ball(Color chosen,String label){
 		super();
 		c = chosen;
		lbl = label;
	}
    public ball(Color chosen){
		super();
		c = chosen;
	}
	public ball(){
			super();
	}
	
	public void paint(Graphics g){
	   g.setColor(c);
	   g.fillOval(0,0,10,10);
	   g.drawString(lbl,11,10);
	}
}
