//
import java.awt.*; public class BA extends java.applet.Applet implements Runnable { //------------- GENERIC STOPPABLE APPLET ------------- Object lock = new Object(); boolean isLocked = false; Thread t; public void init() { if (t == null) { t = new Thread(this); t.start(); } } public void start() { synchronized(lock) { lock.notifyAll(); } isLocked = false; } public void stop() { isLocked = true; } public void run() { try { while (true) { if (isLocked) synchronized(lock) { lock.wait(); } repaint(); t.sleep(30); } } catch(Exception e){ System.out.println(e); }; } //------------- GENERIC DOUBLE BUFFERED APPLET ------------- private Rectangle r = new Rectangle(0,0,0,0); private Image bufferImage = null; protected Graphics bufferGraphics = null; public boolean damage = true; int frame = 0; public void update(Graphics g) { if (r.width != bounds().width || r.height != bounds().height) { bufferImage = createImage(bounds().width, bounds().height); bufferGraphics = bufferImage.getGraphics(); r = bounds(); damage = true; } if (damage || (frame++ % 30) == 0) { damage = false; render(bufferGraphics); if (bufferImage != null) g.drawImage(bufferImage,0,0,this); } } public void render(Graphics g) { } }