Simple double buffering tutorial, no more flickering images.
 
RoadDust's Java Double Buffering Tutorial
Tutorial: Double buffering class for Java Applet.
 
Use double buffering to stop images from flickering in Java.
 

Welcome to RoadDust's Java Applet double buffering tutorial. Double buffering is a technique used to prevent the images from flickering on your Java Applet. You will require this technique especially for games or any application requiring moving images. If you've recently built a Java Applet and noticed flickering while moving the images, then this tutorial is for you.

Java Applet Double Buffering Class.

Pre-made Java double buffering class.

Rather then re-invent the wheel, use this simple, pre-made, Java double buffering class. All you have to do is go into your project, add a new class, and paste the following code as is into the newly added class. For the purpose of this tutorial, I will call the class "daApplet".

Once you have this class as part of your project, you need to go back to whatever class requires the double buffering and change the class definition. Normally your class definition should look something like this.

You need to change it in order for it to extend "daApplet" which is your new class instead of extending "Applet". The altered result would look something like the following.

Of course your class definition will most likely be a lot longer than that if this is for a game, since you may be implementing tons of things to it.

If you did this properly you will find yourself with an application that does not flicker. This technique of double buffering is a great way to stop the images in your Java Applet from flickering.

Why does my image replicate itself with this double buffering class?

If you find that your old picture is replicating itself instead of moving, it is normal given the nature of this double buffering technique. The reason for this is that you are not painting a background before painting your image.

Simply, paint a background image first in your paint method before painting the image. If you want a white background, then simply paint the background white in your paint method before painting the image.

Why use double buffering?

Is double buffering really necessary?

If you are moving an image across your Java Applet and notice that the image is flickering, then double buffering is necessary. This gives the impression that the image is moving more smoothly across the screen.

Double buffering will prevent the annoying blinking pictures. If you find your pictures blinking on the screen as you are repainting, you should definitely use this double buffering class in your application. Anyone building a game will tell you the necessity of double buffering. Go ahead and try it, the difference is stunning and I guaranty you will never design another application without it... unless of course you are not using moving images.

Thank you for visiting RoadDust's double buffering Tutorial.