import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class AskingQuestionDialog {
public static void main(String argv[]) {
JOptionPane pane = new JOptionPane(
"To be or not to be ?\nThat is the question.");
Object[] options = new String[] { "To be", "Not to be" };
pane.setOptions(options);
JDialog dialog = pane.createDialog(new JFrame(), "Dilaog");
dialog.show();
Object obj = pane.getValue();
int result = -1;
for (int k = 0; k < options.length; k++)
if (options[k].equals(obj))
result = k;
System.out.println("User's choice: " + result);
}
}