import java.awt.*;
import java.awt.image.ColorModel;
import java.net.URL;
import java.net.MalformedURLException;
import java.applet.Applet;
 
/**
 *
 *  Extension to base applet class to avoid display flicker
 *
 * @version             1.0, 27 Oct 1995
 * @author Matthew Gray
 *
 * Copyright (C) 1996 by Matthew Gray
 *
 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
 * distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
 * notice appear in all copies and that both that copyright notice
and
 * this permission notice appear in supporting documentation, and
that
 * the name of Matthew Gray or net.Genesis not be used in advertising
or 
 * publicity pertaining to distribution of the software without
specific, 
 * written prior permission.  I make no representations about the 
 * suitability of this software for any purpose.  It is provided "as
is" 
 * without express or implied warranty.
 */
 
public class NoFlickerApplet extends Applet {
  private Image offScreenImage;
  private Graphics offScreenGraphics;
  private Dimension offScreenSize;
  
  public final synchronized void update (Graphics theG)
    {
      Dimension d = size();
      if((offScreenImage == null) || (d.width != offScreenSize.width)
	 || (d.height != offScreenSize.height)) 
        {
          offScreenImage = createImage(d.width, d.height);
          offScreenSize = d;
          offScreenGraphics = offScreenImage.getGraphics();
          offScreenGraphics.setFont(getFont());
        }
      offScreenGraphics.setColor (Color.lightGray);
      offScreenGraphics.fillRect(0,0,d.width, d.height);
      paint(offScreenGraphics);
      theG.drawImage(offScreenImage, 0, 0, null);
	setBackground(java.awt.Color.lightGray);
    }
}