Fast re-drawing of images and patterns on an AWT panel, such as
in an animation, typically results in flashing or flickering effect
if no special techniques are employed. Drawing involved a large
number of graphics operations and flickers result when the drawing
cannot keep up with the number of redraws requested. The degree
of the flickering depends on the speed of the machines but is usually
present even on the fastest platforms.
The flicker can be drastically reduced or eliminated by reducing
the number of drawing operations. The most simple approach to drawing
uses many redundant operations that can be eliminated with the techniques
discussed here:
- Override Update - the update()
method clears the drawing area by drawing a rectangle with the
background color. If the whole area is going to be redrawn anyway
in the paint()
method, then its best to override update()
and not do the clear.
- Clipping - only redraw the
areas that have changed from one frame to the next.
- Double Buffer - save time
by first doing all the drawing to an off screen buffer and then
sending this to the screen in one big transfer rather than in
many small transfers for each drawing operation.
References & Web Resources
Latest update: Dec.3, 2004
|