import java.awt.*; import java.applet.Applet; public class Tilk4 extends Applet implements Runnable{ boolean veel=false; int ooteaeg=300; public void start(){ new Thread(this).start(); } public void stop(){ veel=false; } void uusTilk(){ new Tilk4Loim((int)(300*Math.random()), (int)(200*Math.random()), getGraphics() ).start(); } public void run(){ veel=true; Thread.currentThread().setPriority(Thread.MIN_PRIORITY); while(veel){ uusTilk(); try{Thread.sleep(ooteaeg);}catch(Exception e){} } } static void joonistaTilk(Graphics g, int x, int y){ g.fillOval(x, y, 10, 10); Polygon p=new Polygon(); p.addPoint(x, y+5); p.addPoint(x+10, y+5); p.addPoint(x+5, y-10); g.fillPolygon(p); } public static void main(String argumendid[]){ Frame f=new Frame("Mitu tilka"); Tilk4 t=new Tilk4(); f.add(t); f.setSize(300, 300); f.setVisible(true); t.start(); } } class Tilk4Loim extends Thread{ int x, y; Graphics g; public Tilk4Loim(int ux, int uy, Graphics ug){ x=ux; y=uy; g=ug; } public void run(){ double vahe=0.5; for(int d=0; d<10; d+=2){ g.setColor(Color.blue); g.fillOval(x, y, d, d); try{ Thread.sleep(30); }catch(Exception ex){} g.setColor(Color.white); g.fillOval(x, y, d, d); } for(;y<250; y=(int)(y+vahe), vahe=vahe+0.2){ g.setColor(Color.blue); Tilk4.joonistaTilk(g, x, y); try{ Thread.sleep(30); }catch(Exception ex){} g.setColor(Color.white); Tilk4.joonistaTilk(g, x, y); } for(int d=10; d>0; d--){ g.setColor(Color.blue); g.fillOval(x, y, d, d); try{ Thread.sleep(30); }catch(Exception ex){} g.setColor(Color.white); g.fillOval(x, y, d, d); } } }