GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Problem with drawing shapes on canvas Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with drawing shapes on canvas" Watch "Problem with drawing shapes on canvas" New topic
Author

Problem with drawing shapes on canvas

Adrian Kan
Greenhorn

Joined: Jan 14, 2002
Posts: 4
Hello,
I have spent about 1 week on solving this problem. Please help me out!
After drawing images or shapes on the canvas, I used a windows to cover my drawing. Then when I move the windows away, my image will disappear.
WHY??
Please help me??
Adrian Kan
Greenhorn

Joined: Jan 14, 2002
Posts: 4
Here is the complete source code if you don't understand what i have just said.
http://www.yupapa.com/toybox/demo.java
run it and draw on the canvas.
Cover it with a windows, it will then erase your drawing. Any ideas how to fix that?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Any time that the system detects an infringement on your java window, it will automatically call update, which clears the window and then calls paint(). ONLY the stuff that has been taken care of in the paint() method of the component will get put back.
It is up to the programmer to insure that the paint() method has enough information to completely re-create what was on the component before update() was called. This means taking all that stuff that you have scattered through your mouse methods (2 of which are deprecated by the way) and getting that activity located in the paint() method.
Then you have those mouse methods call repaint() - which forces a call to update and paint() and life is good.
Of course the challenge is to make sure that the paint() method knows what the state of the drawing was at any given time. This excersize is left to the reader (. . . isn't that fun to say ).


"JavaRanch, where the deer and the Certified play" - David O'Meara
Ryan Helton
Greenhorn

Joined: Oct 25, 2001
Posts: 11
Hi Cindy,
"(2 of which are deprecated by the way)"
What do you mean by this?
Thanks
Ryan


Ryan<p>---------------------------------<br />"We will stomp to the top with the wind in our teeth."
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
YUPAPA
Welcome to the Java Ranch, we hope you’ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please re-register under an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!
Ryan
What cindy is saying is that two of the methods in the code YUPAPA referenced are deprecated. They are the mouseDown and mouseDrag methods. both have been replaced. A deprecated method is one that, although it still works, it has been replaced or there is another newer metho that works better and is reccomended.
hope that helps


Dave
 
GeeCON Prague 2014
 
subject: Problem with drawing shapes on canvas