// This is not quite a compilable file. // See notes and comments below. /** A timer which "ticks" on a regular basis. * The sleepInterval in the starting version causes a tick approximatly * 30 times a second. * * To use the timer, create an instance of it, and then call its run() method. * This should only be done ONCE. It's like plugging in a clock. After you * plug it in, it ticks forever. * * No changes should be needed, except where there comments are below. * "FloaterBox" is the class of your drawing panel (called OuijaPanel in P3). * * * This class doesn't necessarily have to be a .java file of its own. */ class FloaterTimer implements Runnable { private FloaterBox fBox; // Change to the type of your drawing panel */ /****** As an arugment, pass in the component that needs periodic repainting. */ public FloaterTimer(FloaterBox fBox) {// Change the type this.fBox = fBox; } /** The unit is milliseconds. */ private final int sleepInterval = 33; public void run() { while (!Thread.interrupted()) { /*** RIGHT HERE ***** This is how your drawing code is activated on each tick. You probably don't need to change this line. */ this.fBox.repaint(); try { Thread.sleep(sleepInterval); } catch (Exception e) { break; //leave the loop } } } //end FloaterTimer }