按特殊按钮退出



我已经创建了一个自定义退出按钮,我希望代码终止,如果该按钮被按下。我怎样才能做到呢?

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);
  }
}

您的错误在这一行:

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

Try this:

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

第一个选项是Yes,第二个选项是No。

相关内容

  • 没有找到相关文章

最新更新