Controlling Flicker
by
Overriding java.awt.Component:update()






The normal implementation of java.awt.Component:update() is
    /**
     * Updates the component. This method is called in
     * response to a call to repaint. You can assume that
     * the background is not cleared.
     * @param g the specified Graphics window
     * @see #paint
     * @see #repaint
     */
    public void update(Graphics g) {
        if (! (peer instanceof java.awt.peer.LightweightPeer)) {
            g.setColor(getBackground());
            g.fillRect(0, 0, width, height);
            g.setColor(getForeground());
        }
        paint(g);
    }
   

If you are repainting the entire figure in the same place with each call to repaint(), there is no need to blank the canvas each time (this is often the source of simple flicker). In this case simply redefine update() as
        public void update(Graphics g) {
        paint(g);
    }
 

In our case, we take advantage of the fact that paint() is called at start-up time (without repaint() and update() being executed) and that subsequent calls to repaint() schedule calls to update(). We override update to just redraw part of the screen and not call paint() again.

For more sophisticated contol of flicker, see the JDH, pp. 440-451.