If else branch never used

290 Views Asked by At

I'm using if else and writing down some codes suddenly happens the else said the branch is never used... but it should work.

The statement looks like this

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

There are 1 best solutions below

4
Ori Marko On BEST ANSWER

Check JOptionPane.showConfirmDialog response and compare with 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");
}