?
Solved

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

Posted on 2011-02-20
10
Medium Priority
?
552 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 34940172
You can say clear Rect over the whole compouonent
0
 
LVL 47

Accepted Solution

by:
for_yan earned 1332 total points
ID: 34940178
g2d.clearRect(0,0,this.getWidth(), this.getHeight()) should work
0
 
LVL 92

Assisted Solution

by:objects
objects earned 668 total points
ID: 34940229
typically you don't clear. for example each time the paintComponent() method of a JComponent is called the 'canvas' is already blank.
 
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 1332 total points
ID: 34940446
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
 

Author Comment

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

Expert Comment

by:mrcoffee365
ID: 37645653
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
ID: 37645654
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 27

Expert Comment

by:mrcoffee365
ID: 37646676
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 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