how do i clear all the shapes i've drawn on a panel using the graphics2d object?

how do i clear all the shapes i've drawn on a panel using the graphics2d object?
wrynnAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
for_yanConnect With a Mentor Commented:
g2d.clearRect(0,0,this.getWidth(), this.getHeight()) should work
0
 
for_yanCommented:
You can say clear Rect over the whole compouonent
0
 
objectsConnect With a Mentor Commented:
typically you don't clear. for example each time the paintComponent() method of a JComponent is called the 'canvas' is already blank.
 
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
for_yanConnect With a Mentor Commented:
I guess in order to claer your component in the class where you have
paint method you set up a boolean value, say,
and then  
you just say

  and in you paint(Graphics g) method first thing
you check this boolean
 and return if it is set:

if(clear)return;

  Then if you need to blank your component, you
just say:

   myPanel.setClear(true);
  repaint();

and it  should clean the panel or canvas for you

 
0
 
wrynnAuthor Commented:
I figured out that I had to draw a white rectangle over the entire screen at the beginning of my paint method.
0
 
mrcoffee365Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for wrynn's comment #36156857

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 
for_yanCommented:
I think three comments should be considered to be a solution
ID: 34940178 (166 points)
ID: 34940229 (166 points)
ID: 34940446 (166 points)

Any one of these can be considered as an accepted solution, the other two
are assisted solution

The comment by wrynn  ID: 36156857
in fact repeats the solution which was mentioned above
0
 
mrcoffee365Commented:
Fine with giving points to experts.  The solution used by the asker is not the same as the suggestions by for_yan, hence the original assignment to the asker.  But experts worked at it, so giving points to them is fine.  The first answer from objects is the correct one, but not what the asker used, so hard to say here.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.