我正在尝试创建一个带有“是”或“否”按钮的消息。然后,根据用户点击“是”或“否”,会出现一个窗口,其中包含特定消息。
以下是我的代码:
以下是我的代码:
public class test{
public static void main(String[] args){
//default icon, custom title
int n = JOptionPane.showConfirmDialog(
null,
"Would you like green eggs and ham?",
"An Inane Question",
JOptionPane.YES_NO_OPTION);
if(true){
JOptionPane.showMessageDialog(null, "HELLO");
}
else {
JOptionPane.showMessageDialog(null, "GOODBYE");
}
System.exit(0);
}
}
现在它会打印HELLO,无论你是否选择是或否。如何让它在用户选择否时显示GOODBYE?