/* Copyright 1996, 1997 Astrel and Jonathan Amsterdam. * All rights reserved. * Permission to use, copy, distribute or modify is * freely granted, provided this notice is included. */ import java.awt.*; import java.applet.*; public class DoubleBufferApplet extends Applet { Image offscreenImage; Graphics offg; public void update(Graphics g) { Dimension d = getSize(); // Create the offscreen buffer if necessary. if (offscreenImage == null || offscreenImage.getWidth(null) != d.width || offscreenImage.getHeight(null) != d.height) { // first time, or after resize offscreenImage = createImage(d.width, d.height); if (offg != null) offg.dispose(); offg = offscreenImage.getGraphics(); } // Clear the buffer to the applet's background color. offg.setColor(getBackground()); offg.fillRect(0, 0, d.width, d.height); offg.setColor(getForeground()); // Call paint with the offscreen buffer. paint(offg); // Draw the buffer to the screen. g.drawImage(offscreenImage, 0, 0, this); } public void destroy() { if (offg != null) offg.dispose(); } }