how can I get my applet to keep its resources after applet.destroy()

T

troy makaro

Hi, I'm using the java plugin version 1.5.0_5 and every time I go from my
web page that has the applet to another web page the applet.destroy() method
occurs and all my resources are closed. My threads are closed, my JFrames
are closed and my PipedInputStream and PipledOutputStream are closed. I
tried storing these resouces in a static field which does keep the objects
but the objects are still dead. Is there any way to keep these resources
alive? Here is a simple test:

public class AppletBase extends JApplet {

public void init() {
JButton button = new JButton("Push me2");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFrame frame = new JFrame("Title");
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.getContentPane().add(new JTree());
frame.pack();
frame.setVisible(true);
}
});
getContentPane().setLayout(new FlowLayout());
getContentPane().add(button);

}

}

In the above example, that frame will close when the browser with the applet
goes to another web page. How can I get the frame to stay?
If I can't do it within the applet sandbox how about if I sign the applet?

Troy

Troy
 
A

Andrew Thompson

troy said:
If I can't do it within the applet sandbox how about if I sign the applet?

No. Browsers (should) destroy the applet and resources
on page exit, though the *browser* should also cache
classes and images etcetera.

You might play tricks with putting the series of pages in
'frames' and placing a 'storage applet' in a hidden frame,
but..

When dealing with applets, there is only one thing you can
rely on. Even if you found a way that worked in one browser,
there would be another browser in which it breaks.
 
T

troy makaro

I think the only way to do it is to sign the applet and then create the
resources in a different thread group. I tried this and it does work.
Troy
 
A

Andrew Thompson

troy said:
I think the only way to do it is to sign the applet and then create the
resources in a different thread group. I tried this and it does work.

<zen question>
In which browser, running which VM?
<zen question>

Where is your page* where I can test that concept
with 4 different browsers running 3 different VM's?

* URL..
 
R

Roedy Green

Is there any way to keep these resources
alive? Here is a simple test:

Put them in a static. That should survive anything but the
classloader being nullified.
 
R

Roedy Green

In the above example, that frame will close when the browser with the applet
goes to another web page. How can I get the frame to stay?
If I can't do it within the applet sandbox how about if I sign the applet?

This is a completely different question from how to hold onto loaded
resources. A Frame is not a resource. Even if I knew, I would not
tell you. That would be the Applet from hell.
 
T

troy makaro

I actually don't want a JFrame. I used it as an example that was small. I'm
more concerned with threads and input/output streams. These die even if they
are in a static field as you suggested in a previous post. I am writing a
terminal emulator that I want imedded in an applet not a frame and if a user
goes from one page and to another page and then returns, I want the terminal
emulator to be exactly where it left off.

Troy
 
R

Roedy Green

I actually don't want a JFrame. I used it as an example that was small. I'm
more concerned with threads and input/output streams. These die even if they
are in a static field as you suggested in a previous post. I am writing a
terminal emulator that I want imedded in an applet not a frame and if a user
goes from one page and to another page and then returns, I want the terminal
emulator to be exactly where it left off.

If your app is independent of the browser, perhaps you should cut the
apron strings and allow the browser to terminate without affecting
you.
See http://mindprod.com/jgloss/javawebstart.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top