need help with the code will not close window buts opens the right window
Code :
@Override
protected void processWindowEvent(WindowEvent e){
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
int exit = JOptionPane.showConfirmDialog(this, "Are you sure? Your Game Will Not be Saved!");
if ((exit == JOptionPane.YES_OPTION)) {
Game_titleMenue s = new Game_titleMenue();
s.setVisible(true);
close();
}
}
else
{
super.processWindowEvent(e);
}
}
private void close() {
WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
}
}
trying to close the jframe that is open and open another jframe to go back to the program selection.
but reopens the jframe that was open ect. try running the coed with 2 jframes and you will see my problem.
:confused:
Re: need help with the code will not close window buts opens the right window
I suggest that you consider changing your GUI structure as no user is going to enjoy using a GUI that opens, closes and throws windows at them willy-nilly. Think of most of the GUI programs that you use including word processors, games and browsers, and you'll see that most of them have one main window (the Java equivalent of a JFrame), that they occasionally show dialogs (the Swing equivalent of a JDialog or JOptionPane), and that they often swap *views* in the main window (the Swing equivalent of using a CardLayout).
Instead I suggest you gear your GUI towards creating JPanel views which will give you the flexibility of placing these views inside of JFrames, JDialogs, other JPanels, or wherever you'd like. If you're not familiar with the CardLayout, I also suggest that you check out the tutorial as it is *very* handy to use.
If on the other hand you absolutely need this current design and are still stuck, consider creating and posting a small compilable and runnable program that demonstrates your problem for us, an SSCCE.
Re: need help with the code will not close window buts opens the right window
will try the GUI resigned did not know a bout that. will look in to it thinks.