如果这听起来像一个愚蠢的问题,我很抱歉,但我到处搜索 JOptionPane 中的自定义按钮。我遇到了如何实现特殊按钮,但我似乎无法在我的程序中使用它。
int choice;
Object[] doors = { "Door 1", "Door 2", "Door 3" };
JFrame frame = new JFrame();
input = "Which door do you choose?";
choice = JOptionPane.showOptionDialog(frame, input,
"Doors",
JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
doors,
doors[2]);
if (car == 1 && choice.equals(doors[0])) {
open = 3; option = 2;
}
if (car == 1 && choice.equals(doors[1])) {
open = 3; option = 1;
}
if (car == 1 && choice.equals(doors[2])) {
open = 2; option = 1;
}
if (car == 2 && choice.equals(doors[0])) {
open = 3; option = 2;
}
if (car == 2 && choice.equals(doors[1])) {
open = 1; option = 3;
}
if (car == 2 && choice.equals(doors[2])) {
open = 1; option = 2;
}
if (car == 3 && choice.equals(doors[0])) {
open = 2; option = 3;
}
if (car == 3 && choice.equals(doors[1])) {
open = 1; option = 3;
}
if (car == 3 && choice.equals(doors[2])) {
open = 2; option = 1;
}
注意:这不是我的整个程序,只是有问题的方面
对话框中的选项完美显示,只是有一个错误说“不能尊重 int”。我想我使用了错误的比较,但是我该如何解决呢?