Java - showConfirmDialog

Опубликовано: 28 Сентябрь 2024
на канале: Dr. Andy Wicks
24,131
93

This video demonstrates the use of the showConfirmDialog in Java. This pops a box onto the screen containing a question or a statement and then displays three buttons underneath; Yes, No and Cancel. The program captures which button was pressed and then acts accordingly.

If you want to use Yes/No only then have:-

int dialogResult = JOptionPane.showConfirmDialog(this, "Your Message", "Title on Box", JOptionPane.YES_NO_OPTION);
if (dialogResult == 0) {
System.out.println("Yes option");
}
else {
System.out.println("No Option");
}