I was looking at different answers for this kind of question but they didn't meet my specifications. I have a class app1.java. It has the public static void main
function in which there is a JOptionPane.showConfirmDialog
object. On clicking yes
, I want to run another java file called "app2.java" and close the current running applocation( i.e. app1.java).
I tried this code:
int response = JOptionPane.showConfirmDialog(null, "Do you want to restart?", "Restart Game?",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (response == JOptionPane.NO_OPTION) {
System.exit(0);
}
else if (response == JOptionPane.YES_OPTION) {
new app2();
}
else if (response == JOptionPane.CLOSED_OPTION) {
System.exit(0);
}
The problem is that on clicking yes, a new window opens but the former one does not close. I cannot try System.exit as it closes both the windows. What should be done?