Flicker free animation

Discussion in 'Java' started by Bob Jackson, Jun 20, 2004.

  1. Bob Jackson

    Bob Jackson Guest

    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
     
    Bob Jackson, Jun 20, 2004
    #1
    1. Advertising

  2. On Sun, 20 Jun 2004 08:34:10 -0700, Bob Jackson wrote:

    > ..I overrode the JFrame's
    > paint() method..


    <http://www.physci.org/guifaq.jsp#2.4>

    You might also check this..
    <http://www.physci.org/launcher.jsp#JAnimateFrame>

    Or, if you are feeling daring, this very
    experimental (but way groovy) code..
    <http://www.physci.org/test/ss/starzoom/index1.html>

    HTH

    [ Note, plese do NOT post to invalid
    Java groups such as comp.lang.java,
    F'Ups set to c.l.j.gui ]

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Jun 20, 2004
    #2
    1. Advertising

  3. Bob Jackson

    Roedy Green Guest

    On Sun, 20 Jun 2004 08:34:10 -0700, "Bob Jackson"
    <> wrote or quoted :

    > 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

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jun 20, 2004
    #3
  4. Bob Jackson

    Bob Jackson Guest

    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


    "Roedy Green" <> wrote in message
    news:...
    > On Sun, 20 Jun 2004 08:34:10 -0700, "Bob Jackson"
    > <> wrote or quoted :
    >
    > > 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
    >
    > --
    > Canadian Mind Products, Roedy Green.
    > Coaching, problem solving, economical contract programming.
    > See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Bob Jackson, Jun 20, 2004
    #4
  5. Bob Jackson

    VisionSet Guest

    "Bob Jackson" <> wrote in message
    news:96lBc.19672$wS2.14943@okepread03...
    > 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.

    --
    Mike W
     
    VisionSet, Jun 20, 2004
    #5
  6. Bob Jackson

    Gawnsoft Guest

    On Sun, 20 Jun 2004 08:34:10 -0700, "Bob Jackson"
    <> wrote (more or less):

    >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
     
    Gawnsoft, Jun 20, 2004
    #6
  7. Bob Jackson wrote:
    > 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
     
    Thomas Weidenfeller, Jun 21, 2004
    #7
  8. Bob Jackson

    ak Guest

    ak, Jun 21, 2004
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer

    Question: flicker on refresh

    VB Programmer, Jul 21, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    684
    VB Programmer
    Aug 6, 2003
  2. Steve C. Orr [MVP, MCSD]

    stop postback flicker

    Steve C. Orr [MVP, MCSD], Dec 15, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    3,265
    Mary Simpson
    Dec 16, 2003
  3. Binny

    Flicker and datagrid

    Binny, Dec 16, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    684
    Binny
    Dec 16, 2003
  4. ujjc001
    Replies:
    8
    Views:
    4,456
    Jason
    Jan 5, 2005
  5. Peter Duniho
    Replies:
    0
    Views:
    900
    Peter Duniho
    Feb 11, 2008
Loading...

Share This Page