Source of DBAnimationApplet.java


  1: import java.awt.*;
  2: 
  3: public abstract class DBAnimationApplet 
  4:     extends AnimationApplet { 
  5: 
  6:   abstract protected void paintFrame(Graphics g); 
  7: 
  8:   final public void update(Graphics g) {
  9:     if (doubleBuffered) {
 10:       if (im == null) {
 11:         im = createImage(d.width, d.height);
 12:         offscreen = im.getGraphics();
 13:       }
 14:       paintFrame(offscreen); 
 15:       g.drawImage(im, 0, 0, this);
 16:     } else { 
 17:       super.update(g); 
 18:     }
 19:   }
 20:   
 21:   final public void paint(Graphics g) {
 22:     paintFrame(g); 
 23:   }
 24:   final public void init() {
 25:     d = getSize();
 26:     initAnimator(); 
 27:   }
 28:   
 29:   protected void initAnimator() {} 
 30: 
 31:   protected DBAnimationApplet(boolean doubleBuffered) {
 32:     this.doubleBuffered = doubleBuffered;
 33:   }
 34:   
 35:   protected DBAnimationApplet() {
 36:     this.doubleBuffered = true; 
 37:   }
 38:   
 39:   protected boolean doubleBuffered;
 40:   protected Image im;
 41:   protected Graphics offscreen;  
 42:   protected Dimension d; 
 43: }