如果其他分支从未使用过

时间:2018-10-22 10:09:13

标签: java swing joptionpane messagedialog

我正在使用if并突然写下一些代码,else表示从未使用过该分支...但是应该可以使用。

语句看起来像这样

JOptionPane.showConfirmDialog(null,full_name+"\n"+number_age+"\n"+gender+"\n"+address+
                 "\n"+birthday+"\n"+cell_no,"CHECK INFORMATION!",JOptionPane.YES_NO_OPTION);
if(true){
    JOptionPane.showMessageDialog(null,"Thank you for Entering");
}else{
    JOptionPane.showMessageDialog(null,"Please Retry");
}

1 个答案:

答案 0 :(得分:1)

检查JOptionPane.showConfirmDialog响应并与JOptionPane.YES_NO_OPTION进行比较:

int answer = JOptionPane.showConfirmDialog(null,full_name+"\n"+number_age+"\n"+gender+"\n"+address+
                 "\n"+birthday+"\n"+cell_no,"CHECK INFORMATION!",JOptionPane.YES_NO_OPTION);
if (JOptionPane.YES_OPTION == answer)) {
    JOptionPane.showMessageDialog(null,"Thank you for Entering");
} else {
    JOptionPane.showMessageDialog(null,"Please Retry");
}