import javax.swing.*; import java.awt.*; import java.awt.event.*; public class EventDemo implements ActionListener{ protected JButton b; public EventDemo(){ JFrame frame = new JFrame("Event Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setPreferredSize(new Dimension(200, 200)); // initialize the button b = new JButton("Click me!"); // add event handling to the button b.addActionListener(this); frame.getContentPane().add(b); frame.pack(); frame.setVisible(true); } public void actionPerformed(ActionEvent e){ b.setText("Thanks!"); } public static void main(String []args){ new EventDemo(); } }