Does it make sense to double buffer like crazy?

Prev      Next

Answer: No Try this applet for comparison.

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

public class CheckersYikes extends Applet implements Runnable {
   Thread runner;
   int xpos;
   Image offscreenImg, checkerImg, backImg;
   Graphics offscreenGraphics, checkerGraphics, backGraphics;

   public void init() {
      offscreenImg = createImage(getSize().width, getSize().height);
      offscreenGraphics = offscreenImg.getGraphics();
      backImg = createImage(getSize().width, getSize().height);
      backGraphics = backImg.getGraphics();
      checkerImg = createImage(100,100);
      checkerGraphics = checkerImg.getGraphics();
      backGraphics.setColor(Color.black);
      backGraphics.fillRect(0,0,100,100);
      backGraphics.setColor(Color.white);
      backGraphics.fillRect(101,0,100,100);
   }

   public void start() {
      runner = new Thread(this);
      runner.start();
   }

   public void run() {
      setBackground(Color.blue);
      while (true) {
         for (xpos=5 ; xpos <= 105; xpos += 4) {
            repaint();
            try { runner.sleep(50); } catch (InterruptedException e) {}
         }
         for (xpos=105 ; xpos > 5; xpos -= 4) {
            repaint();
            try { runner.sleep(50); } catch (InterruptedException e) {}
         }
      }
   }

   public void update(Graphics g) {  paint(g);  }

   public void paint(Graphics g) {
      offscreenGraphics.drawImage(backImg,0,0,this);
      checkerGraphics.setColor(Color.black);
      checkerGraphics.fillRect(0,0,100-xpos,100);
      checkerGraphics.setColor(Color.white);
      checkerGraphics.fillRect(101-xpos,0,100,100);
      checkerGraphics.setColor(Color.red);
      checkerGraphics.fillOval(5,5,90,90);
      offscreenGraphics.drawImage(checkerImg,xpos,0,this);
      g.drawImage(offscreenImg,0,0,this);
   }
}