Solved

Help on removing graphic objects in an applet.

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet requestdispatcher include and forward differences 1 30
MySqlDump not dumping triggers 1 30
how to see all occupied ports on windows 10 laptop 15 61
by zero exception 10 39
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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
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:

808 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