我正在尝试使用"是"或"否"按钮创建消息.然后会出现一个窗口,其中包含某条消息,该消息取决于用户是单击是还是否.
这是我的代码:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
现在它会打印HELLO,无论你是否按下否.当用户选择否时,如何让它显示GOODBYE?