我创建了一个自定义退出按钮,如果按下该按钮,我希望代码终止。我怎样才能做到这一点?
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);
}
}
答案 0 :(得分:2)
您的错误就在这一行:
String[] button1 = {"exit", "next"};
试试这个:
String[] button1 = {"next", "exit"};
第一个选项是是,第二个选项是否。