import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.net.URL; import java.math.*; public class Auto extends Applet implements MouseListener{ int x=100; int y=100; public Auto(){ addMouseListener(this); } public void mousePressed(MouseEvent e){ Graphics g=this.getGraphics(); //x = e.getX(); //y = e.getY(); for(int i=0; i<5;i++){ x = (int)(Math.random()*200); y = (int)(Math.random()*500); new Mobiil(x,y,Toolkit.getDefaultToolkit().getImage("auto.gif")); System.out.println(""+x+" "+y); } } 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 Auto()); f.setSize(200, 200); f.setVisible(true); } class Mobiil extends Thread{ int x,y; Image pilt; Graphics g=Auto.this.getGraphics(); public Mobiil(int x,int y, Image pilt){ this.x=x; this.y=y; this.pilt=pilt; start(); } public void run(){ while(x<400){ g.drawImage(pilt, x, y, null); try{Thread.sleep(50);}catch(Exception wait){} //oodatakse veidi g.setColor(Color.white); //g.fillRect(x-5, y-5, 57, 57); try{Thread.sleep(50);}catch(Exception wait){} x=x+3; } } } }