[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Prevent Applet from being destroyed

Posted on 1998-03-11
5
Medium Priority
?
395 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

656 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