Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Bastet Massri   on Aug 07 In Java Category.

  
Question Answered By: Jennifer Davis   on Aug 07

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

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Exit from frame using button Or get search suggestion and latest updates.


Tagged: