import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class HiirPall3 extends Applet implements MouseListener{ Pall pyydmispall=null; public HiirPall3(){ addMouseListener(this); } double kaugus(int x1, int y1, int x2, int y2){ int dx=x2-x1; int dy=y2-y1; return Math.sqrt(dx*dx+dy*dy); } public void mousePressed(MouseEvent e){ if(pyydmispall==null){ pyydmispall=new Pall(e.getX(), e.getY()); } else { if(kaugus(e.getX(), e.getY(), pyydmispall.x, pyydmispall.y)< pyydmispall.r){ pyydmispall.x=(int)(Math.random()*200); pyydmispall.y=(int)(Math.random()*100); } } } class Pall extends Thread{ int x, y, r=10; Graphics g=HiirPall3.this.getGraphics(); public Pall(int uus_x, int uus_y){ x=uus_x; y=uus_y; start(); } public void run(){ while(y<200){ int jx=x, jy=y; g.setColor(Color.black); g.drawOval(jx-r, jy-r, 2*r, 2*r); try{Thread.sleep(100);}catch(Exception erind){} g.setColor(Color.white); g.drawOval(jx-r, jy-r, 2*r, 2*r); y=y+3; } } } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public static void main(String[] argumendid){ Frame f=new Frame(); f.add(new HiirPall3()); f.setSize(200, 200); f.setVisible(true); } }