/*

	Base animation class - 10/97 O. Lawlor

*/



import java.applet.Applet;

import java.awt.*;

import java.awt.image.*;

import java.lang.InterruptedException;



public class AnimApplet extends Applet

{

	public void start() {

		Thread me=Thread.currentThread();

		while (true)

		{

			repaint();

			try {me.sleep(300);} catch (Exception e) {}

		}

	}

	/*This is key to eliminate flashing.*/

	public void update(Graphics g) {paint(g);}

	

	synchronized public void paint(Graphics g) {redraw(g);}

	

	Graphics img_g=null;

	Image img=null;

	int cached_w=-1,cached_h=-1;

	synchronized void redraw(Graphics g)

	{

		int w = size().width;

		int h = size().height;

		if (img==null||cached_w!=w||cached_h!=h)

		{

			cached_w=w;

			cached_h=h;

			img = createImage(w,h);

			img_g=img.getGraphics();

		}

		eraseBackBuffer(img_g,w,h);

		img_g.setColor(Color.black);

		fillBackBuffer(img_g,g,w,h);

   	g.drawImage(img, 0, 0, this);

	}

	protected void eraseBackBuffer(Graphics win_g,int w,int h) 

	{

		img_g.setColor(Color.lightGray);

		img_g.fillRect(0,0,w,h);

	}

	protected void fillBackBuffer(Graphics g,Graphics win_g,int w,int h) {}

}

