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

Discussion in 'Java' started by troy makaro, Oct 6, 2005.

  1. troy makaro

    troy makaro Guest

    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
     
    troy makaro, Oct 6, 2005
    #1
    1. Advertising

  2. troy makaro wrote:

    > 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.
     
    Andrew Thompson, Oct 7, 2005
    #2
    1. Advertising

  3. troy makaro

    troy makaro Guest

    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

    "troy makaro" <> wrote in message
    news:WRg1f.99552$1i.4803@pd7tw2no...
    > 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
    >
     
    troy makaro, Oct 7, 2005
    #3
  4. troy makaro wrote:

    > 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..
     
    Andrew Thompson, Oct 7, 2005
    #4
  5. troy makaro

    Roedy Green Guest

    On Thu, 06 Oct 2005 21:41:10 GMT, "troy makaro" <>
    wrote or quoted :

    >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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Oct 7, 2005
    #5
  6. troy makaro

    Roedy Green Guest

    On Thu, 06 Oct 2005 21:41:10 GMT, "troy makaro" <>
    wrote or quoted :

    >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.


    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Oct 7, 2005
    #6
  7. troy makaro

    troy makaro Guest

    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


    "Roedy Green" <> wrote in
    message news:...
    > On Thu, 06 Oct 2005 21:41:10 GMT, "troy makaro" <>
    > wrote or quoted :
    >
    >>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.
    >
    >
    > --
    > Canadian Mind Products, Roedy Green.
    > http://mindprod.com Again taking new Java programming contracts.
     
    troy makaro, Oct 7, 2005
    #7
  8. troy makaro

    Roedy Green Guest

    On Fri, 07 Oct 2005 15:46:33 GMT, "troy makaro" <>
    wrote or quoted :

    >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
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Oct 7, 2005
    #8
  9. Roedy Green wrote:
    ...
    > 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


    That's a good idea. I do not think this would be practical
    as an applet or series of applets.
     
    Andrew Thompson, Oct 8, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    583
  2. Ook
    Replies:
    2
    Views:
    358
  3. thunk
    Replies:
    1
    Views:
    359
    thunk
    Mar 30, 2010
  4. thunk
    Replies:
    0
    Views:
    536
    thunk
    Apr 1, 2010
  5. thunk
    Replies:
    14
    Views:
    660
    thunk
    Apr 3, 2010
Loading...

Share This Page