//
import java.awt.*;

public class GenericApplet extends java.applet.Applet implements Runnable
{
   public boolean damage = true;        // you can force a render
   public void render(Graphics g) { }   // you can define how to render

   Image image = null;
   private Graphics buffer = null;
   private Thread t;
   private Rectangle r = new Rectangle(0, 0, 0, 0);

   public void start() { if (t == null) { t = new Thread(this); t.start(); } }
   public void stop()  { if (t != null) { t.stop(); t = null; } }
   public void run() {
      try { while (true) { repaint(); t.sleep(30); } }
      catch(InterruptedException e){};
   }

   public void update(Graphics g) {
      if (r.width != bounds().width || r.height != bounds().height) {
         image = createImage(bounds().width, bounds().height);
         buffer = image.getGraphics();
         r = bounds();
         damage = true;
      }
      render(buffer);
      damage = false;
      paint(g);
   }

   public void paint(Graphics g) {
      if (image != null)
         g.drawImage(image,0,0,this);
   }
}