The DigitalClock doesn't flicker, but this illustrates the technique on a short example. |
public void class DigitalClock extends java.applet.Applet |
implements Runnable |
{ . . . |
Image offscreenImg; |
Graphics og; |
public void init ( ) |
{ offscreenImg = createImage (getSize( ).width, getSize( ).height); |
og = offscreenImg.getGraphics ( ); |
} |
public void paint ( Graphics g ) |
{ og.setFont ( theFont ); |
og.drawString ( theDate.toString ( ), 10, 50 ); |
g.drawImage ( offscreenImg, 0, 0, this); |
} |
public void update ( Graphics g) |
{ paint ( g); } |
} |