/* 
 * AnimationFrame - a double-buffering Frame 
 * with an animation loop
 *
 * Nina Amenta
 * Sept. 2001
 * Based on Jonathan Knudsen's AnimationFrame, greatly simplfied
 * and with little nap between frames provided.
 *
 */

import java.awt.*;

public abstract class AnimationFrame
    extends BufferingFrame 
    implements Runnable // means it can be run in a Thread
  {


  // Constructor
  public AnimationFrame(String title) {
    super(title);  
    
  }

    // Method run in animation loop
    // You need to overwrite this to get anything to move
    public abstract void timeStep();
  
    // The animation loop, run in its own Thread.
    public void run() {
    try {
        // Note weird Java fact:
        // static methods of Thread refer to 
        // CURRENT thread, not all threads.
        while (!Thread.interrupted()) {
          timeStep();  // should move things around, but not draw
          repaint();   // ask AWT to redraw 
          Thread.sleep(30); // sleep for 30 milliseconds
                            // so 30 frames takes 900 milliseconds, 
                            // that is, almost a second.
          }
        }
        catch (InterruptedException e) {};
    }
  
 }

