Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to reset jpanel...  RSS feed

 
Maria Sachhause
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a drawing panel where I can draw lines etc.

Program works like this:

1. First mouse click makes start point (coordinates)
2. Second mouse click makes destination point (coordinates)
3. Line is drawn between those points
4. Third click draw a line from it coordinates toward center of jpanel

problem is this....

How to make Jbutton RESET, which set panel empty(as it was when program where started)without restarting.

What is the easiest way to do that?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maria Sachhause:
....

How to make Jbutton RESET, which set panel empty(as it was when program where started)without restarting.

What is the easiest way to do that?


super.paintComponent(Graphics g)
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some ideas:
1 — you can reset the member variables (x1, y1, ...) to be equal or offscreen, eg, -1 so that they are not drawn when the component repaints itself after you call repaint;
2 — you can use a member variable boolean in your paintComponent method which you control from your event code to turn on/off drawing of the lines.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!