import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ButtonTest { public static class MyActionListener implements ActionListener { public void actionPerformed (ActionEvent e) { Toolkit.getDefaultToolkit().beep(); } } public static void main (String[] args) { JFrame frame = new JFrame ("Program"); JButton button = new JButton ("Click Me"); button.addActionListener (new MyActionListener()); frame.getContentPane().add (button, BorderLayout.CENTER); frame.addWindowListener(new WindowAdapter() { public void windowClosing (WindowEvent e) { System.exit(0); } }); frame.pack (); frame.setVisible(true); } }