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?
Who is Participating?

Improve company productivity with a Business Account.Sign Up

for_yanConnect With a Mentor Commented:
g2d.clearRect(0,0,this.getWidth(), this.getHeight()) should work
You can say clear Rect over the whole compouonent
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.
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:


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


and it  should clean the panel or canvas for you

wrynnAuthor Commented:
I figured out that I had to draw a white rectangle over the entire screen at the beginning of my paint method.
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.
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
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.
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.