?
Solved

Help on removing graphic objects in an applet.

Posted on 2002-05-28
4
Medium Priority
?
221 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 700 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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:
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

771 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