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

        // Display an Option Dialog when a button is pressed.
        // The dialog offers the user a choice of different options.
class SwingOptionFrame6 extends JFrame {
    public SwingOptionFrame6() {
        final int width = 300, height = 100;
        setSize(width,height);
        final Container contents = getContentPane();

        // The button labels.
        final Object[] options = {
            "Orange",
            "Apple",
            "Grape",
            "Cranberry",
        };

        // A button to trigger the dialog.
        JButton activity = new JButton("Drink");
        activity.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                int choice = JOptionPane.showOptionDialog(
                        contents,
                        "Which juice would you prefer?",
                        "Drink Choice",
                        JOptionPane.DEFAULT_OPTION,
                        JOptionPane.QUESTION_MESSAGE,
                        (Icon) null,
                        options,
                        options[0]);
                if(choice >= 0){
                    System.out.println("You selected: "+options[choice]);
                }
                else{
                    System.out.println("You selected: "+choice);
                }
            }
        });

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