Solved

Prevent Applet from being destroyed

Posted on 1998-03-11
5
388 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 100 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

809 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