by Dinesh Thakur Category: Swing

A dialog box ("dialog" for short) is any box, or window, on the screen that you have a dialog with. You can decide to pop up some dialog boxes j to enter information in, or make choices about how a program works. "Other dialogs appear automatically to give you simple messages (such as "Your disk is full") and ask you what you want to do about it.


Some people make a distinction between dialog boxes and alert boxes (where the computer warns you about something) or message boxes (where the computer just tells you about something), but that really only matters if you're a programmer. Everyone will understand what you mean if you call them all dialog boxes.

import java.awt.*;

import java.awt.event.*;
import javax.swing.*;
public class JavaExampleOptionPane
            public static void main( String aa[] )
                    Object[] Btns = {"One", "Two", "Three", "Four" };
                     int Rspns =JOptionPane.showOptionDialog( null, "Message", "Option Pane In
Java",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE, null,Btns, "One" );
                     String Typ = "Undefined";
                     if( Rspns == JOptionPane.YES_OPTION ) { Typ = "Yes"; }
                     if( Rspns == JOptionPane.NO_OPTION ) { Typ = "No"; }
                     if( Rspns == JOptionPane.CANCEL_OPTION ) { Typ = "Cancel"; }
                     System.out.println( Typ + ": " + Rspns );

showOptionDialog 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