1

I have created a custom exit button and i want the code to terminate if that button is pressed. How can i achieve that?

String[] button1 = {"exit", "next"};
//if next is pressed
if (code == JOptionPane.YES_OPTION) {
  JOptionPane.showMessageDialog(
              null, 
              "Knock knock" + "\nWho is there",
              "The Jasmin Project",
              JOptionPane.YES_NO_OPTION);
  int no = JOptionPane.showOptionDialog(null, "Want to view more?",
              "The Jasmin Project",
              JOptionPane.YES_NO_OPTION,
              JOptionPane.INFORMATION_MESSAGE,
              null,
              button1,
              button1[0]);
  //end code if exit is pressed            
  if (no == JOptionPane.NO_OPTION) {
     System.exit(1);
  }
}
afrojuju_
  • 126
  • 1
  • 3
  • 12

1 Answers1

2

Your error is in this line:

String[] button1 = {"exit", "next"};

Try this:

String[] button1 = {"next", "exit"};

The first option is Yes, the second one is No.

desperateCoder
  • 700
  • 8
  • 18