[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Prevent Applet from being destroyed

Posted on 1998-03-11
5
Medium Priority
?
397 Views
Last Modified: 2008-03-10
I have written an applet that loads a different page into the browser frame. I then want the user to be able to return to the page with the applet by hitting the back key or clicking a hyperlink, and the applet must be in the same state as when the page was last visited.

However, I have found that the applet is being destroyed when the new page is loaded, and a new instance of the applet is created when the original page is revisited! This is the behaviour on IE4, and is at odds with what I believe to be the correct theoretical behaviour i.e. that the
stop() method is called when the page is left, and
destroy() is not called until the browser is shut down.

How can I prevent the applet from being destroyed when a new page is loaded?

Here is some code to illustrate this. If this applet is embedded in a HTML page, run in IE4 with the java console displayed, "applet destroyed!" will be displayed in the cosole window as soon as the page is left.

import java.applet.*;
import java.awt.*;
import java.util.*;
import java.net.*;

public class test extends Applet
{
      Applet a;

      public test()
      {
            System.out.println("new applet constructed");
      }

      public void init()
      {
            System.out.println("init");
      }

      public void destroy()
      {
            System.out.println("applet destroyed!");
      }

      public void start()
      {
            System.out.println("start");
      }
      
      public void stop()
      {
            System.out.println("stop");
      }
}
0
Comment
Question by:jduminy
5 Comments
 
LVL 3

Expert Comment

by:gwalters
ID: 1233498
The best way to do what you want is to show the new page in a new window [using showDocument(URL,String)] instead of the one containing the applet.  

There's no way to be sure that when you get back (either through browser history or by hyperlink) that you'll have the same applet.

Posted as a comment since it doesn't really answer your question,  but hopefully will fix your problem.
0
 

Author Comment

by:jduminy
ID: 1233499
Thanks, but I really need to ensure that my original applet instance survives, if at all possible...
0
 
LVL 3

Expert Comment

by:gwalters
ID: 1233500
What I'm trying to tell you is that this is the only way to ensure that:  open in a new window instead of in the window running the applet.
0
 
LVL 3

Expert Comment

by:slok
ID: 1233501
I agree with gwalters.
Take a look at Lycos chat, Java version.
They have it as an applet on another window as well.
0
 
LVL 1

Accepted Solution

by:
datadesign earned 200 total points
ID: 1233502
what about creating a Framed HTML, and just open the new HTML in a Frame
(u can use the showDocument method, and open the link in a frame !!!)

then your applet would be present all the time, and must not be reloaded




0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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 how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

865 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