// Virtual Graphics applet base class

import java.applet.*;
import java.awt.*;

public class Vapplet extends Applet
  {
  Image virtualcontext;

// used to create the image internally
  private void createcontext()
    {
    virtualcontext=createImage(getSize().width,getSize().height);
    }
    
// the next two functions check for
// a null context and create the context if 
// it is null
// this allows us not to override init()
// so that the derived class does not
// have to call our custom init()!
  public Graphics getVirtualGraphics()
    {
    if (virtualcontext==null) createcontext();
    return virtualcontext.getGraphics();
    }
    
  public void paint(Graphics g)
    {
    if (virtualcontext==null) createcontext();
    g.drawImage(virtualcontext,0,0,this);
    }
    
  // prevents flicker
  public void update(Graphics g)
    {
    paint(g);
    }
  }