by Dinesh Thakur

A confirmation dialog box is meant for asking a confirmation question and allows the user to give a yes/no/cancel response. It is created by using the static method showConfirmDialog() of JOptionPane. The general form of showConfirmDialog()method is

public static int showConfirmDialog(Component parentComponent,

Object message)


parentComponent is the frame to which the dialog box is attached

message is the message to be displayed


import javax.swing.JOptionPane;

public class JavaExampleOptionPaneAirlineDialog
   public static void main(String[] as)
      int Slctn;
      boolean Yes;
      Slctn = JOptionPane.showConfirmDialog(null,"Would you Like To Choose Business Class?");
              Yes = (Slctn == JOptionPane.YES_OPTION);
      JOptionPane.showMessageDialog(null,"You Confirmed: " +Yes);

showConfirmDialog Java Example