//RotRing //Demonstrates basic animation loop, primitive animation //Andy Harris, 06/00 import java.awt.*; import java.applet.*; public class RotRing extends Applet implements Runnable { Thread looper; int ringSize = 10; //height of ring int dSize = 10; //difference in ring size int ringY; //placement of ring boolean keepGoing = true; //sentry variable public void start(){ if (looper == null){ looper = new Thread(this); keepGoing = true; looper.start(); } // end if } // end start public void stop(){ keepGoing = false; looper = null; } // end if public void run(){ while (keepGoing){ try { looper.sleep(100); } catch (InterruptedException exc){ System.out.println(exc.getMessage()); } // end try ringSize += dSize; if (ringSize > this.getSize().height - 20){ dSize = -10; } else if (ringSize < 20){ dSize = 10; } // end if //recalculate ring height ringY = (this.getSize().height - ringSize) / 2; repaint(); } // end while loop } // end run public void paint(Graphics g){ g.drawOval(10, ringY, this.getSize().width - 20, ringSize); } // end paint } // end class def