import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Dialog2 extends JFrame 
{
    private JLabel     label1   = new JLabel("Standard Confirm Buttons: ", SwingConstants.RIGHT);
    private JTextField confirm1 = new JTextField("", 15);
    private JLabel     label2   = new JLabel("Custom Choises Buttons: ",   SwingConstants.RIGHT);
    private JTextField confirm2 = new JTextField("", 15);
    private JLabel     label3   = new JLabel("Input String Entered: ",     SwingConstants.RIGHT);
    private JTextField input3   = new JTextField("", 15);

    public static void main(String[] arguments) {
        new Dialog2();
    }

    public Dialog2()                                                //constructor 
    {
        super("Capture Result of Dialogs");                         //call the super constructor
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel pane = new JPanel();
        pane.setLayout(new GridLayout(3, 2));                       //3 row, 2 columns

        pane.add(label1);
        pane.add(confirm1);
        pane.add(label2);
        pane.add(confirm2);
        pane.add(label3);
        pane.add(input3);

        Color c = new Color(200,255,255);   //create an RGB color
        pane.setBackground(c);              //set panel background color    

        setContentPane(pane);
        pack();
        setVisible(true);

        boolean more = true;

        while(more)
        {

            //Alert a message - no return value
            JOptionPane.showMessageDialog(null,                         //parent component 
                    "Please answer the next 3 prompts",                 //message  
                    "Alert Dialog",                                     //dialog box title
                    JOptionPane.INFORMATION_MESSAGE);                   //type of icon to display


            //Confirm for a standard button options
            int response1 = JOptionPane.showConfirmDialog(null,         //parent component                           
                            "Please confirm your purchase",             //message                   
                            "Confirm Dialog",                           //dialog box title                          
                            JOptionPane.YES_NO_CANCEL_OPTION,           //type of option
                            JOptionPane.QUESTION_MESSAGE);              //type of icon to display

            confirm1.setText(response1 + "");


            //Comfirm for a custom button options
            String[] choices = {"Apple","Orange","Banana","Pear"};
            int response2 = JOptionPane.showOptionDialog(null,          //parent component
                                "What is your favorite fruit?",         //message 
                                "Confirm Dialog",                       //dialog box title
                                0,                                      //Yes/No or Yes/No/Cancel? 
                                JOptionPane.QUESTION_MESSAGE,           //type of icon to display
                                null,                                   //custom icon if any
                                choices,                                //buttons defined above
                                choices[0] );                           //default button

            String chosen = (response2 >= 0) ? choices[response2] : "[X]";
            confirm2.setText(response2 +" - "+ chosen);


            //Prompt for text
            String response3 = JOptionPane.showInputDialog(null,        //parent component
                                   "Enter any Text:",                   //message 
                                   "Prompt Dialog",                     //dialog box title                           
                                   JOptionPane.PLAIN_MESSAGE);          //plain = no icon

            input3.setText(response3);


            //Play again? Yes/No/Cancel
            int response4 = JOptionPane.showConfirmDialog(null, "Do it again?");                                
                                                                                          
            if (response4 != JOptionPane.YES_OPTION )       //if not YES
                more = false;                               //~ (no,cancel,closed)          
        }
    }
}