For example:
int n = JOptionPane.showConfirmDialog( frame, "Would you like green eggs and ham?", "An Inane Question", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { } else if (n == JOptionPane.NO_OPTION) { } else { }
Alternative with showOptionDialog :
Object[] options = {"Yes, please", "No way!"}; int n = JOptionPane.showOptionDialog(frame, "Would you like green eggs and ham?", "A Silly Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { } else if (n == JOptionPane.NO_OPTION) { } else { }
See How to make dialogs for more details.
EDIT: showInputDialog
String response = JOptionPane.showInputDialog(owner, "Input:", ""); if ((response != null) && (response.length() > 0)) { }
tenorsax
source share