home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1998 February / VPR9802A.ISO / APP_DEMO / VC / SAMPLES.BIN / DoubleBufferPanel.java < prev    next >
Text File  |  1997-10-27  |  979b  |  48 lines

  1. /*
  2.  * @(#)DoubleBufferPanel.java    1.2 97/01/14 Jeff Dinkins
  3.  *
  4.  * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  */
  7.  
  8. import java.awt.*;
  9. import java.applet.*;
  10.  
  11. public class DoubleBufferPanel extends Panel {
  12.     
  13.   Image offscreen;
  14.  
  15.   /**
  16.    * null out the offscreen buffer as part of invalidation
  17.    */
  18.   public void invalidate() {
  19.       super.invalidate();
  20.       offscreen = null;
  21.   }
  22.  
  23.   /**
  24.    * override update to *not* erase the background before painting
  25.    */
  26.   public void update(Graphics g) {
  27.       paint(g);
  28.   }
  29.  
  30.   /**
  31.    * paint children into an offscreen buffer, then blast entire image
  32.    * at once.
  33.    */
  34.   public void paint(Graphics g) {
  35.       if(offscreen == null) {
  36.          offscreen = createImage(getSize().width, getSize().height);
  37.       }
  38.  
  39.       Graphics og = offscreen.getGraphics();
  40.       og.setClip(0,0,getSize().width, getSize().height);
  41.       super.paint(og);
  42.       g.drawImage(offscreen, 0, 0, null);
  43.       og.dispose();
  44.   }
  45.  
  46. }
  47.  
  48.