Domanda

The confirm dialog box is not recognizing the no option. It prints yes no matter what i press. Can anyone help?

if(e.getSource()==b5)
{
int db=0;
JOptionPane.showConfirmDialog(null, "Exit this        

screen?","Exit",JOptionPane.YES_NO_OPTION);

if(db==JOptionPane.NO_OPTION)
{
System.out.println("no");
}
else if(db==JOptionPane.YES_OPTION)
{
System.out.println("yes");

}
}
È stato utile?

Soluzione 2

You havent assign JOptionPane return value to db, it should be

db = JOptionPane.showConfirmDialog(null, "Exit this screen", Exit",JOptionPane.YES_NO_OPTION);

Altri suggerimenti

Your code leaves db as zero, instead of assigning the return value of showConfirmDialog to it. You meant to write this.

int db = JOptionPane.showConfirmDialog(null, "Exit this screen?", "Exit", JOptionPane.YES_NO_OPTION);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top