Canvas blinks when constantly repainted

I am creating an application that contains java.awt.Canvas to display a sequence of related nodes, as in a graph. when editing, the last point is attached to the mouse cursor using java.awt.geom.Line2D so that it is repainted every time the user moves the mouse, and this causes a really disgusting -flashy effect on the screen.

I have done this before, and I know that the solution was so easy and did not need really hard code, but to get around the paint(g) , repaint(g) and update(g) methods, despite this, I can not solve it and hope someone can help me!

Thank you very much in advance!:)

+4
source share
2 answers

You need to do double buffering to get rid of flicker. Loads examples if you use Google for this.

Found a previous question that contains more information. Here is another example .

+4
source

Here is a double buffering tutorial http://download.oracle.com/javase/tutorial/extra/fullscreen/doublebuf.html

The idea is that you draw on the screen, and then when you finish drawing the whole image, you draw that image on the screen.

+1
source

All Articles