Solved

Help on removing graphic objects in an applet.

Posted on 2002-05-28
4
218 Views
Last Modified: 2010-03-31
If I have used the paint() method to draw a number of line and rectangular objects (in the process or creating graphs), how do I go about removing those graphics, so make room for other objects?

One possible solution I found was to simply cover up the graphic with something the color of the background, but this won't work if the background changes color in certain parts of the applet, and will also obscure any other objects (buttons, labels) I don't want to remove.

Is there a method I can use to simply destroy all Graphic objects I have initialized?
0
Comment
Question by:esotericlete
[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
  • 3
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 7041045
Painting done in your paint() method is not persistent. The paint() method is called whenever your component is required to be repainted. So for example a line you paint in one call may not necessarilt still be there in the next call. As a side note you should also never call the paint method directly, it is used as a callback.
If you make the first call in your paint() method a paint a filled rectangle the size of the component then you'll have a blank canvas to work with.
If you can post your code I can help you further.
0
 
LVL 92

Accepted Solution

by:
objects earned 175 total points
ID: 7041062
eg.

public void paint(Graphics g)
{
   Dimension size = getSize();
   g.setColor(getBackground());
   g.fillRect(0, 0, size.width, size.height);
   g.setColor(getForeground());
   
   // Do your painting now
}
0
 

Author Comment

by:esotericlete
ID: 7297782
I solved it since, but completely forgot I had the question left here.
0
 
LVL 92

Expert Comment

by:objects
ID: 7297797
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

691 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