import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class StandardDialogTester extends JFrame {
    public StandardDialogTester (String title) {
        super(title);
        setLayout(new GridLayout(3, 3));

        JButton aButton;

        add(aButton = new JButton("Plain Message Box"));
        aButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null,
                    "This is a plain message !!!",
                    "Read This",
                    JOptionPane.PLAIN_MESSAGE);
            }});

        add(aButton = new JButton("Warning Message Box"));
        aButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null,
                    "Don't eat yellow snow.",
                    "Warning",
                    JOptionPane.WARNING_MESSAGE);
            }});

        add(aButton = new JButton("Error Message Box"));
        aButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
               JOptionPane.showMessageDialog(null,
                   "Your program has stopped working !",
                   "Error",
                   JOptionPane.ERROR_MESSAGE);
            }});

        add(aButton = new JButton("Information Message Box"));
        aButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
               JOptionPane.showMessageDialog(null,
                   "You better pass the final exam or else ...",
                   "Information",
                   JOptionPane.INFORMATION_MESSAGE);
            }});

        add(aButton = new JButton("Confirmation Dialog Box"));
        aButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int result = JOptionPane.showConfirmDialog(null,
                                 "Do you want me to erase your hard drive ?",
                                 "Answer this Question",
                                 JOptionPane.YES_NO_OPTION);
                if (result == 0)
                    System.out.println("OK, I'm erasing it now ...");
                else
                    System.out.println("Fine then, you clean it up!");
            }});

        add(aButton = new JButton("Confirmation Dialog Box with Cancel"));
        aButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int result = JOptionPane.showConfirmDialog(null,
                                 "Do you want to overwrite the file ?",
                                 "Answer this Question",
                                 JOptionPane.YES_NO_CANCEL_OPTION);
                switch(result) {
                    case 0: System.out.println("OK, but don't come crying to me once its gone"); break;
                    case 1: System.out.println("Well you should pick a new name then"); break;
                    case 2: System.out.println("OK, I'll ask you again later"); break;
                }
            }});

        add(aButton = new JButton("Multiple Option Dialog Box"));
        aButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Object[] options = {"Outstanding", "Excellent", "Good", "Fair", "Poor"};
                int result = JOptionPane.showOptionDialog(null,
                                 "How would you rate your vehicle's performance ?",
                                 "Pick an Option",
                                 JOptionPane.DEFAULT_OPTION,
                                 JOptionPane.QUESTION_MESSAGE,
                                 null,
                                 options,
                                 options[0]);
                System.out.print("You have rated your vehicle's performance as " + options[result]);
                if (result < 3)
                    System.out.println("We are glad you are pleased.");
                else
                    System.out.println("Please explain why.");
            }});

        add(aButton = new JButton("Input Dialog Box"));
        aButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String inputValue = JOptionPane.showInputDialog("Please input your name");
                System.out.println("Your name is " + inputValue);
            }});

        add(aButton = new JButton("Chooser Dialog Box"));
        aButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Object[] options = {"Apple", "Orange", "Strawberry", "Bannana", "Cherry"};
                Object selectedValue = JOptionPane.showInputDialog(null,
                                           "Choose your favorite fruit",
                                           "Fruit Information",
                                           JOptionPane.INFORMATION_MESSAGE,
                                           null,
                                           options,
                                           options[1]);
                System.out.println(selectedValue + "s sure do taste yummy.");
            }});

        setDefaultCloseOperation(EXIT_ON_CLOSE);
        pack(); //chooses reasonable window size based on component prefered sizes
     }

    public static void main(String args[]) {
        new StandardDialogTester("Standard Dialog Tester").setVisible(true);
    }
} 