// Called when the applet needs to be painted
// calls the flicker free updating system
public void paint (Graphics g) {
update(g);
} // end of paint
// Draw the applet without flicker
// Use synchronized
public synchronized void update(Graphics g) {
// get the size of the applet
int xW = size().width ;
int xH = size().height ;
if ((xW != aW) || (xH != aH) || (offScreen == null)) {
// initialise the double buffering screen
try {
offScreenImage = createImage (xW, xH);
offScreen = offScreenImage.getGraphics ();
} catch (Exception e) {
offScreen = null;
}
aW = xW ;
aH = xH ;
// get Image size
iW = img.getWidth(this) ;
iH = img.getHeight(this) ;
}
if ((offScreen!=null) && b) {
paintApplet(offScreen);
g.drawImage(offScreenImage,0,0,this);
} else
paintApplet(g);
} // end of update
// Draw applet
public void paintApplet(Graphics g) {
g.setColor(Color.white ) ;
g.fillRect(0, 0, aW, aH) ;
g.drawImage(img, xPos, yPos, this) ;
g.setColor(Color.red ) ;
g.drawString("double buffer : " + b, 10, yPos) ;
}
|