A very good tutorial on how to reduce flicker in Java GUI applications is given at:
Excerpt from the article:
Double buffering means to paint all the things in the paint() method to an offscreen image. If all things that have to be painted, are painted, this image is copied to the applet screen. The method does the following in detail:
- Generates a new offscreen-image by using createImage and stores this image in a instance variable( = generate an empty image)
- Call getGraphics to get graphic context for this image
- Draw everything (including to clear the screen completely) on the offscreen image ( = draw image in the background)
- When finished, copy this image over the existing image on the screen. ( = draw image in the foreground)
This technique means that the picture is already painted before it is copied to the screen. When copying the image to the foreground the old pixels are overlayed by the new ones. There won't be any flickering picture anymore because there is not a millisecond where you see an empty screen!
The only disadvantage of the double buffering is, that it produces a large amount of data and every image is drawn two times (offscreen and when copying to the screen). But in most cases and on a fast computer this is much better than wasting time on finding an other solution!