import java.awt.*; import java.applet.Applet; public class Pallike extends Applet implements Runnable{ Pall2 p; Image pilt; public Pallike(){ p=new Pall2(); new Thread(this).start(); } public void joonista(){ if(pilt==null) pilt=createImage(220, 220); if(pilt!=null){ Graphics piltg=pilt.getGraphics(); piltg.setColor(Color.white); piltg.fillRect(0, 0, 220, 220); piltg.setColor(Color.black); piltg.drawLine(90, 0, 90, 95); piltg.drawOval(p.x()-10, p.y()-10, 20, 20); this.getGraphics().drawImage(pilt, 0, 0, this); } } public void run(){ while(true){ joonista(); Thread.yield(); try{Thread.sleep(20);}catch(Exception e){} } } public static void main(String argumendid[]){ Frame f=new Frame("Pallikesed"); f.add(new Pallike()); f.setSize(220, 220); f.setVisible(true); } } class Pall2 extends Thread{ double x=100, y=100, dx, dy; int vasak=5, ulal=10, parem=200, all=180, kesk=100; 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(){ setPriority(Thread.NORM_PRIORITY-2); while(true){ if(x>parem)dx=-Math.abs(dx); if(y>all)dy=-Math.abs(dy); if(xkesk-10 && dx<0)dx=Math.abs(dx); else if(ykesk-20 && dx>0)dx=-Math.abs(dx); x+=dx; y+=dy; yield(); try{Thread.sleep(20);}catch(Exception e){} } } }