How does an applet behave when reloaded?

Posted on 2006-10-26
Medium Priority
Last Modified: 2010-03-31
Hello experts,

I already have an open question in this vein, but I wanted to ask something more general here to help my understanding of the issue.

My Applet is part of a drawing tool, and it loads in an image to be drawn on from a URL. The JPanel that the image sits in automatically resizes itself when an image is loaded in. The problem I'm having is when the Applet is reloaded with a different image. When this happens, there are a couple of problems:

1. The JPanel for the image remains the same size, essentially cropping a larger image.
2. Whatever items were drawn onto the first image remain when the Applet is reloaded with a different image.

So it looks like the Objects created in the first load remain after the reload. Why is this? Is there a way to stop it happening?


Question by:mb2297
LVL 92

Expert Comment

ID: 17817263
1. if you weant the panel to resize when a new image is loaded you need to implement that reloading yourself.
2. again the painting isimplemented in your applet, so if the applet is reloaded you need to clear anything that you are already painting. This can be implemnted in the start() method as I mentioned in your other q. The start() method will get called whenever the applet is loaded.
LVL 26

Accepted Solution

Tomas Helgi Johannsson earned 2000 total points
ID: 17817775

Take a look at this info (The lifecycle of an Applet) : http://www.iam.ubc.ca/guides/javatut99/applet/overview/lifeCycle.html.

What you have to do is override the init, start, stop and destroy methods and
do some initialization / "cleanup" in those methods depending on what you want to achive when
applet is in those states.

   Tomas Helgi  

Author Comment

ID: 17859697
Thanks for the clear explanation Tomas. Those links were very useful.


Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

621 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