import javax.swing.*; import java.awt.event.*; class ButtonListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(null, "You pushed the button!!"); } } public class EventExample { public static void main(String[] args) { // create and set up the window. JFrame frame = new JFrame("Button Example!"); // make the program close when the window closes frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // add a button object JButton button = new JButton("Push Me!"); button.addActionListener(new ButtonListener()); frame.getContentPane().add(button); // display the window. frame.pack(); frame.setVisible(true); } }