import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class Kapsauss extends Applet implements ActionListener { Button Aeglasemax = new Button("<--"); Button Kiiremax = new Button("-->"); int X1=10, Y1=50; int X2=20, Y2=50; int X3=30, Y3=50; int X4=40, Y4=50; int X5=50, Y5=50; int kiirus = 80; public Kapsauss() { add(Aeglasemax); add(Kiiremax); Aeglasemax.addActionListener(this); Kiiremax.addActionListener(this); new Roomamine(); } public void actionPerformed(ActionEvent e) { if(e.getSource() == Aeglasemax) kiirus = kiirus + 10; if(e.getSource() == Kiiremax) kiirus = kiirus - 10; System.out.println(kiirus+"\n"); } public void paint(Graphics g) { g.drawOval(X1,Y1,10,10); g.drawOval(X2,Y2,10,10); g.drawOval(X3,Y3,10,10); g.drawOval(X4,Y4,10,10); g.drawOval(X5,Y5,10,10); } class Roomamine extends Thread { public Roomamine() { start(); } public void run() { while (true) { try{ if (X5>900) { X1=10; Y1=50; X2=20; Y2=50; X3=30; Y3=50; X4=40; Y4=50; X5=50; Y5=50; repaint(); } Y3=Y3-10; Y4=Y4-10; repaint(); try{Thread.sleep(kiirus);} catch(Exception viga){} Y2=Y2-10; X1=X1+10; repaint(); try{Thread.sleep(kiirus);} catch(Exception viga){} Y3=Y3-10; X1=X1+10; X2=X2+10; repaint(); try{Thread.sleep(kiirus);} catch(Exception viga){} X5=X5+10; X4=X4+10; X3=X3+10; Y3=Y3+10; repaint(); try{Thread.sleep(kiirus);} catch(Exception viga){} X5=X5+10; X4=X4+10; Y4=Y4+10; X3=X3+10; X2=X2+10; repaint(); try{Thread.sleep(kiirus);} catch(Exception viga){} X5=X5+10; X4=X4+10; X3=X3+10; Y3=Y3+10; Y2=Y2+10; X2=X2+10; X1=X1+10; repaint(); try{Thread.sleep(kiirus);} catch(Exception viga){} }catch(Exception e) { System.out.println("Probleem: "+e);} } } } public static void main(String[] argumendid) { Frame f=new Frame(); f.add(new Kapsauss()); f.setSize(1000, 100); f.setVisible(true); } }