Avoid flickering

hi how can we avoid flickering of the applet when displaying an animation ? regards raghav mathur

Raghav.

Dirk Schreckmann

Sheriff

Posts: 7023

posted 14 years ago

double buffering I'd bet you could turn up a couple of decent explanations by searching this forum, the awt forum, and one or two of the java in general forums. Note: the search page link is at the top right of this page. Good Luck.

Originally posted by Dirk Schreckmann: double buffering I'd bet you could turn up a couple of decent explanations by searching this forum, the awt forum, and one or two of the java in general forums. Note: the search page link is at the top right of this page. Good Luck.

Raghav.

Raghav Mathur

Ranch Hand

Posts: 641

posted 14 years ago

I,am still not getting the idea behind Double Buffering . Please if anybody could explain it to me without giving any URL links . Thanks in advance raghav

The normal operation of repaint() (then update(Graphics) then paint(Graphics)) is to clear the display area then draw it again (probably using new information). Considering an animation, rather than displaying the new graphics immediately to the user's display from the paint method's automatic Graphics object, the new image is first drawn to an offscreen image. After the new image is drawn, the Graphics object from this offscreen image is then displayed to the user's display through the automatic Graphics object in paint. To further remove the flickering, the update(Graphics) method should be overridden to avoid the call to clear the display before repainting. A performance enhancement to consider would be to describe a clipping area where the new graphics will appear (as often the entire display area is not changing during an animation) and repaint this clipping area only. To paraphrase: 1. draw new graphics to offscreen image 2. get offscreen image's graphics object 3. do not clear the entire display area 4. display this new graphics object When I get a chance I'll dig out a simple example animation and describe what's going on in it. Otherwise, I'm pretty sure it's posted somewhere in this forum or the awt forum within the past five months. Good Luck.