953 import javax.swing.*; //This is the final package name. //import com.sun.java.swing.*; //Used by JDK 1.2 Beta 4 and all //Swing releases before Swing 1.1 Beta 3. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ClickMe extends JFrame implements ActionListener { private static String labelPrefix = "Number of button clicks: "; private JButton button; private JLabel label1, label2; private JTextField edit1, edit2; public ClickMe() { label1 = new JLabel("Name"); edit1 = new JTextField(); label2 = new JLabel("Address"); edit2 = new JTextField(); button = new JButton("OK"); button.addActionListener(this); /* * An easy way to put space between a top-level container * and its contents is to put the contents in a JPanel * that has an "empty" border. */ JPanel pane = new JPanel(); pane.setBorder(BorderFactory.createEmptyBorder( 20, //top 20, //left 20, //bottom 20) //right ); pane.setLayout(new GridLayout(0, 2)); pane.add(label1); pane.add(edit1); pane.add(label2); pane.add(edit2); getContentPane().add(pane, BorderLayout.CENTER); } public void actionPerformed(ActionEvent e) { String name = JOptionPane.showInputDialog(this, "Please enter your name"); if (name != null) { JOptionPane.showMessageDialog(this, "Hello, " + name +". Do you like this amazing program?", "", JOptionPane.PLAIN_MESSAGE); } } public static void main(String[] args) { try { UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) { } //Create the top-level container and add contents to it. JFrame frame = new ClickMe(); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; frame.setTitle("ClickMe"); frame.addWindowListener(l); frame.pack(); frame.setLocation(200,200); frame.setVisible(true); } } . 0