import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Drag extends Applet {
private int x=-5,y=-5;
public void init(){
MouseMotionHandler mh=new MouseMotionHandler(this);
addMouseMotionListener(mh);
}
public void paint (Graphics g){
g.fillOval(x,y,3,3);
}
public void update (Graphics g)
{
paint(g);
}
public void setCor(int x1,int y1){
x=x1;
y=y1;
repaint();
}
}
class MouseMotionHandler extends MouseMotionAdapter{
private Drag dragger;
public MouseMotionHandler(Drag d)
{
dragger=d;
}
public void mouseDragged(MouseEvent e)
{
dragger.setCor(e.getX(),e.getY());
}
}
Thursday, July 16, 2009
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment