import java.awt.*; import java.util.*; import java.awt.event.*; import javax.swing.*; public class OptionPaneTest extends JFrame implements ActionListener { public OptionPaneTest() { super("OptionPaneTest"); //Build a menu that creates dialogs. JMenuBar mb = new JMenuBar(); JMenu m = new JMenu("dialogs"); m.add("input dialog").addActionListener(this); m.add("message dialog").addActionListener(this); m.add("confirm dialog").addActionListener(this); m.add("option dialog").addActionListener(this); mb.add(m); setJMenuBar(mb); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setSize(300, 300); setVisible(true); } public void actionPerformed(ActionEvent e) { //Show the dialog and print the return value. if (e.getActionCommand().equals("input dialog")) { //Create an input dialog. System.out.println("return from input dialog: " + JOptionPane.showInputDialog(this, "Vilka är bäst?", "Fotboll", JOptionPane.QUESTION_MESSAGE, null, null, "BAJEN")); } else if (e.getActionCommand().equals("message dialog")) { //Create a message dialog. System.out.println("no return from message dialog"); JOptionPane.showMessageDialog(this, "Bajen är bäst i sta'n", "Fotboll", JOptionPane.INFORMATION_MESSAGE, new ImageIcon("hif-log.gif")); } else if (e.getActionCommand().equals("confirm dialog")) { //Create a confirm dialog. System.out.println("return from confirm dialog: " + JOptionPane.showConfirmDialog(this, "Du håller väl på Bajen?", "Fotboll", JOptionPane.YES_NO_OPTION)); } else if (e.getActionCommand().equals("option dialog")) { //Create an option dialog. System.out.println("return from option dialog: " + JOptionPane.showOptionDialog(this, "Vilka är bäst?", "Fotboll", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, new ImageIcon("hif-log.gif"), new Object[] { "Hammarby", "HIF", "Bajen" }, "Bajen")); } } public static void main(String args[]) { new OptionPaneTest(); } }