Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > repaint without flickering

Reply
Thread Tools

repaint without flickering

 
 
Georg Andersson
Guest
Posts: n/a
 
      05-17-2004
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...
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      05-17-2004
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 ]
 
Reply With Quote
 
 
 
 
VisionSet
Guest
Posts: n/a
 
      05-17-2004


"Georg Andersson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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


 
Reply With Quote
 
Mark Sandford
Guest
Posts: n/a
 
      05-17-2004
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/tutor...buffering.html

Hope this helps, MS.
 
Reply With Quote
 
perry
Guest
Posts: n/a
 
      05-17-2004
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...


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      05-17-2004
On 17 May 2004 07:18:00 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (Georg
Andersson) wrote or quoted :

>very ugly flickering...


see http://mindprod.com/jgloss/flicker.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Silvio Bierman
Guest
Posts: n/a
 
      05-17-2004

"Georg Andersson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: java.awt.Frame - How to repaint without background update MaciekL Java 2 08-05-2011 07:48 PM
java.awt.Frame - How to repaint without background update MaciekL Java 1 08-05-2011 11:36 AM
animation without flickering/double buffering dhavalshah Java 0 12-26-2008 02:16 AM
Re-direction without flickering Jens Lenge HTML 9 04-08-2005 07:30 AM
Re: Flickering effect SEWilson ASP .Net 0 08-23-2003 03:59 AM



Advertisments