I’m trying to make a console for a java game, in an applet. The console is an independant Frame with a TextArea, used to show loading/downloading progression.
I’m running into some problems when I try to hide the console on closing.
Here is the simplified code :
//Method inherited from the Applet class
public void init() {
console = new Frame();
console.setSize(500, 300);
console.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
console.setVisible(false);
}
});
consoleText = new TextArea();
consoleText.setSize(500, 300);
console.add(consoleText);
console.setVisible(true);
gameThread = new Thread() {
public void run() {
mainLoop();
}
};
gameThread.start();
}
The thread “gameThread” simply hang when I close the Frame “console”. Even when I replace “console.setVisible(false);” with “console.setExtendedState(Frame.ICONIFIED);”, the thread still hang without any warning.
While running the applet in a browser, I have to kill the process in the task manager. Very annoying.
Using a JFrame instead does the exact same thing, except the bug is harder to reproduce.
I just want the user to be able to get rid of the console.
Does anybody have an idea ? Thanks !
I think that you shouldn’t be using a Frame/JFrame for this but rather a JDialog, since the window is behaving as a dialog. Also be sure that you’re using a JApplet rather than an Applet.
Edit
Note that I cannot reproduce your problem based on your displayed code snippet. Consider creating and posting an SSCCE that would show us the problem directly.
Edit 2
My SSCCE that does not reproduce your problem:
Edit 3
My SSCCE using a JDialog: