public static void main(String[] args) {
JFrame frame = new JFrame("Frame");
Object[] options = {
"Dice roll",
"Magic 8 ball"
};
int a1 = JOptionPane.showOptionDialog(frame,
"Would you like to roll the dice " + "or use the Magic 8 ball?",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[1]);
if (a1 != 0) {
Object[] options = {
"Dice roll", // error
""
};
int a2d = JOptionPane.showOptionDialog(frame, // error
"do you want dice roll 1 " + "or dice roll 2?",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[1]);
}
}
我想要它,以便带有按钮的窗口将是我可以使用的变量 if语句,但如果我复制代码并更改按钮,则表示“Object [] options”已被定义为变量,变量“int a2d”是错误。