1 | The DigitalClock doesn't flicker, but this illustrates the technique on a short example. |
2 | public void class DigitalClock extends java.applet.Applet |
3 | implements Runnable |
4 | { . . . |
5 | Image offscreenImg; |
6 | Graphics og; |
7 | public void init ( ) |
8 | { offscreenImg = createImage (getSize( ).width, getSize( ).height); |
9 | og = offscreenImg.getGraphics ( ); |
10 | } |
11 | public void paint ( Graphics g ) |
12 | { og.setFont ( theFont ); |
13 | og.drawString ( theDate.toString ( ), 10, 50 ); |
14 | g.drawImage ( offscreenImg, 0, 0, this); |
15 | } |
16 | public void update ( Graphics g) |
17 | { paint ( g); } |
18 | } |