Для лучшего понимания, как это работает!
int n = JOptionPane.showConfirmDialog(null, "Yes No Cancel", "YesNoCancel", JOptionPane.YES_NO_CANCEL_OPTION);
if(n == 0)
{
JOptionPane.showConfirmDialog(null, "You pressed YES\n"+"Pressed value is = "+n);
}
else if(n == 1)
{
JOptionPane.showConfirmDialog(null, "You pressed NO\n"+"Pressed value is = "+n);
}
else if (n == 2)
{
JOptionPane.showConfirmDialog(null, "You pressed CANCEL\n"+"Pressed value is = "+n);
}
else if (n == -1)
{
JOptionPane.showConfirmDialog(null, "You pressed X\n"+"Pressed value is = "+n);
}
OR
int n = JOptionPane.showConfirmDialog(null, "Yes No Cancel", "YesNoCancel", JOptionPane.YES_NO_CANCEL_OPTION);
switch (n) {
case 0:
JOptionPane.showConfirmDialog(null, "You pressed YES\n"+"Pressed value is = "+n);
break;
case 1:
JOptionPane.showConfirmDialog(null, "You pressed NO\n"+"Pressed value is = "+n);
break;
case 2:
JOptionPane.showConfirmDialog(null, "You pressed CANCEL\n"+"Pressed value is = "+n);
break;
case -1:
JOptionPane.showConfirmDialog(null, "You pressed X\n"+"Pressed value is = "+n);
break;
default:
break;
}