so, im trying to catch a cancel button click from a JOptionPane, then send the exception up to the window controller, have it destroy the JFrame the exception came from, then start over with the main JFrame of the program.
as that's probably convoluted, i'll post some code.
//from inside the JFrame try { difficulty = (String) JOptionPane.showInputDialog(null, "What difficulty would you like?", "Game", JOptionPane.QUESTION_MESSAGE, null, dificultyChoices, dificultyChoices[0]); } catch(HeadlessException ex) { //wc is a window controller wc.canceled(this); }//from the window controller public void canceled(JFrame callingWindow) { callingWindow.dispose(); //createWindow() draws the window i want to replace callingWindow createWindow(); }
the problem with this is that the original JFrame goes right ahead executing its next line of code. but, of course, since it's just been dispose()'d, it throws a NullPointerException and crashes.
how should i actually be implementing this?