import java.awt.*; import java.applet.Applet; import java.awt.event.*; public class Pallid extends Applet implements ActionListener, Runnable{ public int punane=10, roheline=10, sinine=10; Pall2 pall3, pall5; Image pilt; TextField tf1=new TextField("10"); Label silt=new Label("Sujuvus (0-100)"); public int kiirus=10; public Pallid(){ add (silt); add (tf1); tf1.addActionListener(this); pall3=new Pall2(); pall5=new Pall2(); new Thread(this).start(); } public void joonista(){ if(pilt==null) pilt=createImage(300, 300); if(pilt!=null){ Graphics piltg=pilt.getGraphics(); piltg.setColor(Color.white); piltg.fillRect(0, 0, 300, 300); piltg.setColor(Color.green); punane= (int)(250*Math.random()); sinine=(int)(250*Math.random()); roheline=(int)(250*Math.random()); piltg.fillOval(pall3.x()-10, pall3.y()-10, 10, 10); piltg.fillOval(pall5.x()-10, pall5.y()-10, 10, 10); piltg.setColor(new Color(punane,sinine,roheline)); piltg.drawLine(pall3.x()-5, pall3.y()-5, pall5.x()-5, pall5.y()-5); this.getGraphics().drawImage(pilt, 0, 0, this); } } public void run(){ while(true){ joonista(); try{Thread.sleep(kiirus);}catch(Exception e){} } } public void actionPerformed(ActionEvent e){ kiirus=Integer.parseInt(tf1.getText()); if ((kiirus<0)|(kiirus>100)){ kiirus=10; tf1.setText("10"); } } public static void main(String argumendid[]){ Frame f=new Frame("Pallid"); f.add(new Pallid()); f.setSize(300, 320); f.setVisible(true); f.addWindowListener(new Raamikuular()); } } class Pall2 extends Thread{ double x=100, y=100, dx, dy; int vasak=10, ulal=10, parem=290, all=290; public Pall2(){ dx=5*Math.random(); dy=5*Math.random(); start(); } public int x(){ return (int)x; } public int y(){ return (int)y; } public void run(){ while(true){ if(x>parem)dx=-Math.abs(dx); if(y>all)dy=-Math.abs(dy); if(x