by Dinesh Thakur Category: Swing

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

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles