Solved

Help on removing graphic objects in an applet.

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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
use lov values 2 72
How to determine if a string is a valid SHA value 7 43
Eclipse Java import and method not resolved 4 78
hashmap order 17 42
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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

749 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