Solved

Prevent Applet from being destroyed

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

760 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

23 Experts available now in Live!

Get 1:1 Help Now