所以,我已经在这段代码上被困了大约一个星期了,我想让代码在用户选择“No'”时发送错误消息。或者'取消'但是我收到一个错误,告诉我NO和CANCEL不是变量。有没有人对如何克服这个问题有任何建议?
int mc = JOptionPane.QUESTION_MESSAGE;
int bc = JOptionPane.YES_NO_CANCEL_OPTION;
int ch = JOptionPane.showConfirmDialog (null, "Select:", "Title", bc, mc);
if (bc == NO)
{
JOptionPane.showInputDialog("Sorry, you cannot continue without agreeing to the rules.");
}
else if (bc == CANCEL)
{
JOptionPane.showInputDialog("Sorry, you cannot continue without agreeing to the rules.");
}
else
{
JOptionPane.showInputDialog("Thank you, you may continue!");
}
答案 0 :(得分:1)
这一切都解释为in the JOptionPane Javadoc。
在您提供的代码中,您点击的按钮由showConfirmDialog
的返回值标识,您已将ch
分配给bc
,不是if (ch == JOptionPane.NO_OPTION) {
...
}
else if (ch == JOptionPane.CANCEL_OPTION) {
...
}
else {
...
}
。在你的情况下,逻辑应该是
Application.ActiveExplorer.Selection.Item(1)