Flicker free animation

B

Bob Jackson

Hey guys,

I am attempting to achieve flicker-free animation, but am having some
issues. I created a JFrame containing a JPanel. I overrode the JFrame's
paint() method to display a background image in the JPanel and then
superimpose another image on top of it (a car that moves). Unfortunately,
whenever there is movement, both the background and car flicker. I don't
quite understand why this is occurring - JFrame's update() description
indicates that it does not clear the screen so I thought that wouldn't have
been the issue (I overrode the update to just call paint() just for good
measure also). A couple interesting/perplexing observations: When I remove
the super.paint() call in my overridden method, the flickering stops (of
course I then don't get a couple of button's drawn on the screen like I want
either) and I also tried making setting the opaque flag of the JPanel to
false, but that didn't do anything. Can anyone offer any advice?

Thanks

Bob
 
R

Roedy Green

I overrode the JFrame's
paint() method to display a background image in the JPanel

In Swing, you override paintComponent, not paint.

also experiment with setOpaque
 
B

Bob Jackson

Thanks Roedy - overriding paintComponent did the trick! (As to what the diff
between the two is I am not sure - paint() redraws the entire dialog which
somehow causes a flicker?)

Bob
 
V

VisionSet

Bob Jackson said:
Thanks Roedy - overriding paintComponent did the trick! (As to what the diff
between the two is I am not sure - paint() redraws the entire dialog which
somehow causes a flicker?)

Swing uses double buffering by default, this is where an offscreen graphics
object is rendered, and then swapped in to replace the on-screen one, this
makes for seamless animation. The double buffering is implemented through
the paintComponent method. Flicker is likely when a component is not double
buffered.
 
G

Gawnsoft

Hey guys,

I am attempting to achieve flicker-free animation, but am having some
issues. I created a JFrame containing a JPanel. I overrode the JFrame's
paint() method to display a background image in the JPanel and then
superimpose another image on top of it (a car that moves). Unfortunately,
whenever there is movement, both the background and car flicker. I don't
quite understand why this is occurring - JFrame's update() description
indicates that it does not clear the screen so I thought that wouldn't have
been the issue (I overrode the update to just call paint() just for good
measure also). A couple interesting/perplexing observations: When I remove
the super.paint() call in my overridden method, the flickering stops (of
course I then don't get a couple of button's drawn on the screen like I want
either) and I also tried making setting the opaque flag of the JPanel to
false, but that didn't do anything. Can anyone offer any advice?

super.paint() is (unless you override it), in effect, a clear screen.



--
Cheers,
Euan
Gawnsoft: http://www.gawnsoft.co.sr
Symbian/Epoc wiki: http://html.dnsalias.net:1122
Smalltalk links (harvested from comp.lang.smalltalk) http://html.dnsalias.net/gawnsoft/smalltalk
 
T

Thomas Weidenfeller

Bob said:
Thanks Roedy - overriding paintComponent did the trick! (As to what the diff
between the two is I am not sure - paint() redraws the entire dialog which
somehow causes a flicker?)

You might want to read a little bit about the Swing architecture. Sun
has a paper online in the TSC. A reference can also be found in the
comp.lang.java.gui FAQ.

BTW: comp.lang.java is not a valid newsgroup for several years now.

BTW2: Your question is not that important that it needs to be
cross-posted to three groups.

/Thomas
 
A

ak

super.paint() is (unless you override it), in effect, a clear screen.this is right only for AWT, swing's paint() is _very_ complex!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top