repaint without flickering

Discussion in 'Java' started by Georg Andersson, May 17, 2004.

  1. hi

    i have a litte code, that draws a line while the mouse is pressed and
    dragged. the line sould allways lead from the startpoint to the
    current point. so it is necessary, that the line is deleted and
    repainted on every MouseMotionEvent. i thought i just use the
    repaint-method. but this results in very ugly flickering...

    what would be the correct way for this problem?

    any help will be greatly appreciated...
     
    Georg Andersson, May 17, 2004
    #1
    1. Advertisements

  2. On 17 May 2004 07:18:00 -0700, Georg Andersson wrote:

    > i have a litte code,


    Applet or JApplet? Command line or
    GUI'd application perhaps?

    >..that draws a line
    > while the mouse is pressed and dragged.


    Best group for this is ..
    <http://www.physci.org/codes/javafaq.jsp#cljg>

    > ..i thought i just use the
    > repaint-method. but this results in very ugly flickering...


    But I think this is an FAQ.
    <http://www.physci.org/guifaq.jsp#2.4>

    For an example of renderring in ..
    well you did not state Swing or
    AWT, so, for both.
    <http://www.physci.org/launcher.jsp#JAnimateFrame>
    <http://www.physci.org/launcher.jsp#AnimateFrame>

    [ follow the links to see the
    code and the exmple run ]
     
    Andrew Thompson, May 17, 2004
    #2
    1. Advertisements

  3. Georg Andersson

    VisionSet Guest

    "Georg Andersson" <> wrote in message
    news:...
    > i have a litte code, that draws a line while the mouse is pressed and
    > dragged. the line sould allways lead from the startpoint to the
    > current point. so it is necessary, that the line is deleted and
    > repainted on every MouseMotionEvent. i thought i just use the
    > repaint-method. but this results in very ugly flickering...
    >
    > what would be the correct way for this problem?


    If you listen for points with a mousemotion listener as you probably are
    doing.
    Add them to a two Polygons.

    Have your paint method paint the master Polygon and empty the other
    (unpainted)Polygon.

    call repaint with repaint(unpainted.getBounds());

    The crucial thing is to use the repaint(Rectangle) method that only repaints
    the area you specify; after all, the stuff painted last time hasen't
    changed, why paint it again?

    --
    Mike W
     
    VisionSet, May 17, 2004
    #3
  4. Georg Andersson wrote:
    > hi
    >
    > i have a litte code, that draws a line while the mouse is pressed and
    > dragged. the line sould allways lead from the startpoint to the
    > current point. so it is necessary, that the line is deleted and
    > repainted on every MouseMotionEvent. i thought i just use the
    > repaint-method. but this results in very ugly flickering...
    >
    > what would be the correct way for this problem?
    >
    > any help will be greatly appreciated...


    It flickers because of the number of drawing operations being carried
    out upon the screen, to prevent this you would need to implement
    'double-buffering'. This is where the image is drawn off-screen and
    only the final image drawn as a whole to the screen.

    Sun, as ever, have a tutorial showing how to achieve this with the
    BufferedImage class:
    http://java.sun.com/docs/books/tutorial/2d/images/doublebuffering.html

    Hope this helps, MS.
     
    Mark Sandford, May 17, 2004
    #4
  5. Georg Andersson

    perry Guest

    there's a few examples on sun's website that focus's solely on
    minimizing flickering. do a simple search on java.sun.com

    - perry

    Georg Andersson wrote:
    > hi
    >
    > i have a litte code, that draws a line while the mouse is pressed and
    > dragged. the line sould allways lead from the startpoint to the
    > current point. so it is necessary, that the line is deleted and
    > repainted on every MouseMotionEvent. i thought i just use the
    > repaint-method. but this results in very ugly flickering...
    >
    > what would be the correct way for this problem?
    >
    > any help will be greatly appreciated...
     
    perry, May 17, 2004
    #5
  6. Georg Andersson

    Roedy Green Guest

    Roedy Green, May 17, 2004
    #6
  7. "Georg Andersson" <> wrote in message
    news:...
    > hi
    >
    > i have a litte code, that draws a line while the mouse is pressed and
    > dragged. the line sould allways lead from the startpoint to the
    > current point. so it is necessary, that the line is deleted and
    > repainted on every MouseMotionEvent. i thought i just use the
    > repaint-method. but this results in very ugly flickering...
    >
    > what would be the correct way for this problem?
    >
    > any help will be greatly appreciated...


    If you are talking about a moving drag-style line or box simply use XOR
    drawing mode. It is very simple and you do not need repaint calls (which
    actually cause most flickering).

    Silvio Bierman
     
    Silvio Bierman, May 17, 2004
    #7
    1. Advertisements

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. yop

    Flickering on Listbox control

    yop, Aug 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    538
  2. vinay

    Flickering

    vinay, Aug 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    656
    S. Justin Gengo
    Aug 27, 2003
  3. Manohar

    How to Avoid Flickering?

    Manohar, Nov 6, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,403
    Rajesh.V
    Nov 6, 2003
  4. Praveen Balanagendra via .NET 247

    Reduce Flickering while Refreshing

    Praveen Balanagendra via .NET 247, May 13, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    474
    Praveen Balanagendra via .NET 247
    May 13, 2004
  5. Jens Lenge

    Re-direction without flickering

    Jens Lenge, Apr 7, 2005, in forum: HTML
    Replies:
    9
    Views:
    2,690
    humbads
    Apr 8, 2005
  6. dhavalshah
    Replies:
    0
    Views:
    455
    dhavalshah
    Dec 26, 2008
  7. MaciekL
    Replies:
    1
    Views:
    1,107
    supercalifragilisticexpialadiamaticonormalizeringe
    Aug 5, 2011
  8. MaciekL
    Replies:
    2
    Views:
    2,218
    Ian Shef
    Aug 5, 2011
Loading...