All you need to do is to implement an ActionListener(just add the words
"implements ActionListener" in your class name declaration) , add it to your
frame(mostly inside its constructor) as shown below:
public YourClass(){
your code......
..........
addActionListener(this); //adding action listener to the object
being constructed
}
Then you have to implement the listeners method . This is must or ur
class will never compile
public void actionPerformed(ActionEvent ae){
//use the following method if u have many buttons
if (ae.getSource() == YourButtonobject) {
System.exit(0);
}
}