Solved

Help on removing graphic objects in an applet.

Posted on 2002-05-28
4
183 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
  • 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.

758 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

21 Experts available now in Live!

Get 1:1 Help Now