import java.awt.*;
import javax.swing.*;
import java.awt.event.*;


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);
}
}
}
);

frame.add(jbClose);
frame.pack();
frame.setVisible(true);
}
}