Solved

How does an applet behave when reloaded?

Posted on 2006-10-26
3
244 Views
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?

Thanks,
Matt.



0
Comment
Question by:mb2297
3 Comments
 
LVL 92

Expert Comment

by:objects
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.
0
 
LVL 25

Accepted Solution

by:
Tomas Helgi Johannsson earned 500 total points
ID: 17817775
    Hi!

Take a look at this info (The lifecycle of an Applet) : http://www.iam.ubc.ca/guides/javatut99/applet/overview/lifeCycle.html.
                                                                           http://www.iam.ubc.ca/guides/javatut99/applet/overview/appletMethods.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.

Regards,
   Tomas Helgi  
0
 

Author Comment

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

Matt.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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…

910 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

24 Experts available now in Live!

Get 1:1 Help Now