import java.awt.*;
import java.applet.*;

public class Applet1 extends  Applet
{	
public int posx,posy;
int click; int dx,dy,a,b;


public void init()
{
a=50;
b=30;
posx=posy=10;
click=0;
setBackground(Color.blue);
setForeground(Color.white);
}

public void paint(Graphics g)
{
g.drawRect(posx,posy,a,b);
g.drawString("Hola",posx+15,posy+20);
}

public boolean mouseMove(Event e,int x,int y)
{
if (click==1)
	{
	posx=x-dx;
	posy=y-dy;repaint();
	}
else
if(click==2)
{
	a=x;
	b=y;
	repaint();
	click=0;
}
	 return true;
}
public boolean mouseDown(Event e, int x,int y)
{
	if(x>posx+10 && x<posx+40 && y>posy+10&&y<posy+20)
		if(click==0)
			{dx=x-posx; dy=y-posy; click=1;}
		else click=0;
	else
		if(x==posx || x==posx+a || y==posy || y==posy+b)
			if(click==0)
			{dx=x-posx; dy=y-posy;click=2;}
			else click=0;
return true;
}

}
