import java.awt.*; import java.applet.*; public class DoubleBuf extends Applet { int appwidth, appheight; // the actual buffers Image ibuf; Graphics gbuf; public void setAppWidth(int w) { appwidth = w; } public void setAppHeight(int h) { appheight = h; } // initialization for the offscreen buffer final public void init() { appwidth = this.getSize().width; appheight = this.getSize().height; setBackground(Color.black); ibuf = createImage(appwidth, appheight); gbuf = ibuf.getGraphics(); } // a repaint that sleeps a given number of milliseconds public void repaint(int ms) { try { Thread.sleep(ms); } catch(Exception e) { }; super.repaint(); } // a double buffered version of update public void update(Graphics g) { gbuf.setColor(Color.black); gbuf.fillRect(0,0,appwidth,appheight); paint(gbuf); g.drawImage(ibuf,0,0,this); } }