Solved

Prevent Applet from being destroyed

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

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 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…
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…
This video teaches viewers about errors in exception handling.
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 …

943 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

5 Experts available now in Live!

Get 1:1 Help Now