import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class P extends Applet implements MouseMotionListener, Runnable{ int ooteaeg=10; //ms boolean veel=true; double x1=0; double y1=0; double x2=50; double y2=70; double kiirendus=0.05; public P(){ addMouseMotionListener(this); new Thread(this).start(); } public void mouseMoved(MouseEvent e){ x2=e.getX(); y2=e.getY(); } public void joonista(){ Graphics g=this.getGraphics(); if(g!=null){ g.setColor(Color.white); g.fillRect(0, 0, getSize().width, getSize().height); g.setColor(Color.red); g.fillOval((int)x2, (int)y2, 10, 10); g.setColor(Color.black); g.drawOval((int)x1, (int)y1, 10, 10); if (x1y2){ x1=x1+((x2-x1)*kiirendus); y1=y1-((y1-y2)*kiirendus); } if (x1>x2 && y1x2 && y1>y2){ x1=x1-((x1-x2)*kiirendus); y1=y1-((y1-y2)*kiirendus); } } } public void run(){ while(veel){ joonista(); try{ Thread.sleep(ooteaeg); } catch(Exception e){e.printStackTrace();} } } public void mouseDragged(MouseEvent e){ } public static void main(String argumendid[]){ Frame f=new Frame(); f.add(new P()); f.setSize(200, 200); f.setVisible(true); } }