Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browsing kills applet - how to prevent it?

Status
Not open for further replies.

Nojd

Programmer
Apr 16, 2002
5
SE
I've made a java game that I run in a separate window. No problem. I launch it in a separate window from an applet that simply is a start button. That works well.

But when the browser window with the start button is used to go to some other page, the game window disappears (is destroyed). How do I prevent that?

I'm sure the solution is very simple and has something to do with threads and the Runnable interface, but I haven't been able to figure it out...

A few details:
JDK 1.4
Code:
// The applet which simply is a start button
public class HelloApplet extends JApplet implements ActionListener {
  // ...
  public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(HELLO)) {
      Hello h = new Hello();
    }
  }
}

// The game
public class Hello extends JFrame implements ActionListener, Runnable {
  // ...
  public void run() {
  }
  // This method is run when the Exit button is clicked
  public void actionPerformed(ActionEvent e) {
    if(e.getActionCommand().equals(EXIT)) {
      this.dispose();
    }
  }
}

Thanks!
/Nojd
 
I thought this would be easily solved, even if I haven't been able to find the solution. Anyone? Please?

In case anyone is interested, the game I made is called Kalaha and is a variant of the African board game Mancala. Here it is:
 
Hmm, I think it might be a Java security feature. Is your applet signed and made to run as a trusted applet, I imagine if the first applet is stopped and is unsigned, thus untrusted then the second would be stopped and hence in a way destroyed b/c it has been opened by that first applet thus I think that it's owned by the first applet. Like to hear the solution if you figure it out.

JavaDude32
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top