Two Laptop Bag
The moose likes Swing / AWT / SWT and the fly likes Flickering of Canvas Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Flickering of Canvas" Watch "Flickering of Canvas" New topic

Flickering of Canvas

manu g

Joined: Mar 18, 2001
Posts: 5
i have used AWT for constructing a ImageDrawing tool,for that i used a canvas as the drawing my tool box i have options such as Line,Circle,Rectangle,Freeline etc.the method which i am using is as follows
1.i record all the points in which line or circle is drawn
2. all the points are recorded in a Vector
3.every time i finished drawing something i redraw all the points that ihave recorded earlier
Now the problem is
after a lot of drawing the canvas flickers which unables me to see what i am drawing,i used update() in the code,but it shows me another problem,when ever i draw a colorline or something else
it shows me a number of lines,after minimize if i maximaize the scren it shows the correct image ie what i have drawn,removing all other lines
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

It sounds like you are having refresh problems.... you need to override update() ( if you have not already, you mentioned something about using update in your post. ), and use double buffering. Double buffering is an offscreen image that you draw to and then send to the screen all at once, so the user will not see the redraws.
Here is an example of how you would do it.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
manu g

Joined: Mar 18, 2001
Posts: 5
thank u for ur reply it did work very well,hoping 2 get ur help more
I agree. Here's the link:
subject: Flickering of Canvas
jQuery in Action, 3rd edition