import java.awt.Component;

public class Anim extends Thread {
	private Component toAnimate;		// Components have repaint() method, calls update(g)
	private int FPS;
	private long msDelay;
	private boolean running = false;	

	public Anim(Component toAnimate, long FPs) {
		this.toAnimate = toAnimate;
		this.FPS = FPS;
		msDelay = (FPS^-1)*1000;
		running = true;
	}
	
	// Starts or restarts animation
	public void go() {
		if (!running) {
			running = true;
			start();
		}
	}
	
	// Stops animation
	public void stp() {
		running = false;
	}

	// calls repaint method of toAnimate FPS times per second.
	public void run() {
		while(running) {			
			toAnimate.repaint();
			try { wait(msDelay); } catch (InterruptedException e) { }
		}		
	}
}
