gpt4 book ai didi

java - 按特殊按钮退出

转载 作者:行者123 更新时间:2023-11-30 03:53:46 25 4
gpt4 key购买 nike

我创建了一个自定义退出按钮,我希望在按下该按钮时代码终止。我怎样才能实现这一目标?

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

试试这个:

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

第一个选项是"is",第二个选项是“否”。

关于java - 按特殊按钮退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23767232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com