import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.net.URL; import java.math.*; import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class Auto1 extends Applet implements ActionListener{ int x=100; int y=100; TextField tf=new TextField("50"); Button nupp=new Button("Kiirenda"); public Auto1(){ add(nupp); add(tf); tf.addActionListener(this); nupp.addActionListener(this); } int viivitus; int kordi=8; Image pilt1=Toolkit.getDefaultToolkit().getImage("auto.gif"); Image pilt2=Toolkit.getDefaultToolkit().getImage("1.gif"); public void actionPerformed(ActionEvent e){ //x = e.getX(); //y = e.getY(); x = (int)(Math.random()*200); y = (int)(Math.random()*500); new Mobiil(x,y); System.out.println(""+x+" "+y); } public static void main(String[] argumendid){ Frame f=new Frame(); f.add(new Auto1()); f.setSize(200, 200); f.setVisible(true); } class Mobiil extends Thread{ int x,y; Image pilt1; Image pilt2; int viivitus=Integer.parseInt(tf.getText().trim()); ; Graphics graf=Auto1.this.getGraphics(); public Mobiil(int x,int y){ this.x=x; this.y=y; this.pilt1=Toolkit.getDefaultToolkit().getImage("auto.gif"); this.pilt2=Toolkit.getDefaultToolkit().getImage("1.gif"); start(); } public void run(){ while(x<400){ graf.drawImage(pilt1, x, y, null); try{Thread.sleep(viivitus);}catch(Exception wait){} //oodatakse veidi graf.drawImage(pilt2, x, y, null); graf.setColor(Color.white); //g.fillRect(x-5, y-5, 57, 57); try{Thread.sleep(viivitus);}catch(Exception wait){} x=x+3; } } } }