Showing a Dialog Box
// Modal dialog with OK button
String message = "Line1\nLine2";
JOptionPane.showMessageDialog(frame, message);
// Modal dialog with yes/no button
int answer = JOptionPane.showConfirmDialog(frame, message);
if (answer == JOptionPane.YES_OPTION) {
// User clicked YES.
} else if (answer == JOptionPane.NO_OPTION) {
// User clicked NO.
}
// Modal dialog with OK/cancel and a text field
String text = JOptionPane.showInputDialog(frame, message);
if (text == null) {
// User clicked cancel
}
Post a comment