Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with drawing shapes on canvas

 
Adrian Kan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ).
 
Ryan Helton
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cindy,
"(2 of which are deprecated by the way)"
What do you mean by this?
Thanks
Ryan
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic