Show a confirmation dialog made by JOptionPane and check the result in Java
Description
The following code shows how to show a confirmation dialog made by JOptionPane and check the result.
Example
// ww w.ja va 2 s . c o m
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) {
int result = JOptionPane.showConfirmDialog(null,
"Close this application?");
if (result == JOptionPane.YES_OPTION) {
System.exit(0);
} else if (result == JOptionPane.NO_OPTION) {
System.out.println("Do nothing");
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »