import java.applet.*; import java.awt.*; import java.util.*; import java.lang.*; public class Ring extends Applet implements Runnable{ Color esi=new Color(0,100,0); Color taust=new Color(255, 255, 255); Graafika gr=new Graafika(); Thread jooksja=new Thread(this); int rx=10, ry=10, rxkiirus=5, rykiirus=5; Graphics g=this.getGraphics(); public void stop(){jooksja=null;} public void start(){if(jooksja==null)jooksja=new Thread(this);} public void run(){ Date aeg=new Date(); long a1=0, a2; while(jooksja!=null){ try {Thread.sleep(100-(aeg.getTime()-a1));a1=aeg.getTime();} catch (InterruptedException e){} liiguta(); a2=new java.util.Date().getTime(); g.drawString(a2+" ", 100, 100); }} /*public boolean mouseDown(Event e, int mx, int my){ Graphics g=this.getGraphics(); g.setColor(esi); gr.ring(g, 10, 10, 20); return true;}*/ public void liiguta(){ Graphics g=this.getGraphics(); Rectangle r=this.bounds(); g.setColor(taust); gr.ring(g, rx, ry, 20); //if((rx>1)!=(rx<3))rx++; if((rx+rxkiirus+10>r.x)||(rx+rxkiirus-10<0)) rxkiirus=-rxkiirus; if((ry+rykiirus+10>r.y)||(ry+rykiirus-10<0))rykiirus=-rykiirus; rx+=rxkiirus; g.setColor(esi); gr.ring(g, rx, ry, 20); } public void paint(Graphics g){g.drawOval(10, 10, 15, 15);} }