문제

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");

}
}
도움이 되었습니까?

해결책 2

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

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

다른 팁

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top