File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to reset jpanel... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to reset jpanel..." Watch "How to reset jpanel..." New topic
Author

How to reset jpanel...

Maria Sachhause
Greenhorn

Joined: Nov 30, 2005
Posts: 10
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
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10375
    
    8

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)


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to reset jpanel...