Program Structure

An outline of the basic program structure for double buffering images is given below. It follows the strategy outlined in the previous section. In the next section, an example program using this structure is presented.

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class DoubleBuf extends Applet implements Runnable, MouseListener  {

  Image offscreenImage;
  Graphics offscreenImageG;

// ************* init
    public void init ()  {
      runThread = new Thread ( this );
      runThread.start ();
}  // end init

// ************* run thread

    public void run ()  {
      // draw on offscreenImage, using offscreenImageG
      repaint ();
    }  // end run

// ************* paint

    public void paint ( Graphics g )  {
        g.drawImage ( offscreenImage, 0, 0, this );
    }  // end paint


}  // end DoubleBuf