public class ActionListenerTest ...{ public static void main(String[] args) ...{ JFrame frame = new JFrame("Button Test"); frame.setDefaultCloSEOperation(JFrame.EXIT_ON_CLOSE);
final JButton jbClose = new JButton("Close the Frame"); jbClose.addActionListener(new ActionListener () ...{ public void actionPerformed(ActionEvent e) ...{ if (e.getSource().equals(jbClose)) ...{ System.exit(0); } } } );