I have often come across this way of registering an action listener.
Though I have been using this method recently but I don't understand how's and why's of this
Here is one :{
submit=new JButton("submit");
submit.addActionListener(new ActionListener(){ // line 1
public void actionPerformed(ActionEvent ae) {
submitActionPerformed(ae);
}
}); //action listener added
} Method that is invoked :
public void submitActionPerformed(ActionEvent ae) {
// body
}
In this method, I don't need to implement ActionListener. Why?
Also, please explain what the code labeled as line 1
does.
Please explain the 2 snippets clearly.