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

        // Display a Confirm Dialog when a button is pressed.
class SwingOptionFrame3 extends JFrame {
    public SwingOptionFrame3() {
        final int width = 300, height = 100;
        setSize(width,height);
        final Container contents = getContentPane();

        // A button to trigger the dialog.
        JButton advice = new JButton("Advice");
        advice.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                int choice = JOptionPane.showConfirmDialog(
                                contents,
                                "Do you really want to go out without an umbrella?",
                                "Sanity Check",
                                JOptionPane.DEFAULT_OPTION,
                                JOptionPane.WARNING_MESSAGE);
                switch(choice){
                    case JOptionPane.CANCEL_OPTION:
                        System.out.println("Ok, think again.");
                        break;
                    case JOptionPane.CLOSED_OPTION:
                        System.out.println("You'll regret it.");
                        break;
                    case JOptionPane.NO_OPTION:
                        System.out.println("A wise decision.");
                        break;
                    case JOptionPane.YES_OPTION:
                        System.out.println("You'll regret it.");
                        break;
                }
            }
        });

        // A panel to hold the buttons in the frame.
        JPanel panel = new JPanel();
        panel.add(advice);
        panel.add(new QuitJButton());
        contents.add(panel,"South");
    }
}
