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

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

        // A button to trigger the dialog.
        JButton locate = new JButton("Locate");
        locate.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                Object response = JOptionPane.showInputDialog(
                        contents,
                        "www.jawasoft.com not found",
                        "Please supply a new URL",
                        JOptionPane.ERROR_MESSAGE);
                if(response == null){
                    System.out.println("The dialog was closed or cancelled.");
                }
                else if(response instanceof String){
                    String s = (String) response;
                    System.out.println("You typed: "+s);
                }
                else{
                    System.out.println("You selected: "+response.toString());
                }
            }
        });

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