Solved

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

Posted on 2011-02-20
10
545 Views
Last Modified: 2012-05-11
how do i clear all the shapes i've drawn on a panel using the graphics2d object?
0
Comment
Question by:wrynn
10 Comments
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
You can say clear Rect over the whole compouonent
0
 
LVL 47

Accepted Solution

by:
for_yan earned 333 total points
Comment Utility
g2d.clearRect(0,0,this.getWidth(), this.getHeight()) should work
0
 
LVL 92

Assisted Solution

by:objects
objects earned 167 total points
Comment Utility
typically you don't clear. for example each time the paintComponent() method of a JComponent is called the 'canvas' is already blank.
 
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 333 total points
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:wrynn
Comment Utility
I figured out that I had to draw a white rectangle over the entire screen at the beginning of my paint method.
0
 
LVL 26

Expert Comment

by:mrcoffee365
Comment Utility
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
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
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
 
LVL 26

Expert Comment

by:mrcoffee365
Comment Utility
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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now