java - How does this method work? -


I have often come to this method of registering an action listener.

Although I am using this method recently but I am not able to understand how it is and why

here is one: {

  submit = new JButton ("submit"); Submit.addActionListener (New Actionist) (// Line 1 Public Zero Action Action (Action Avenue) {submitActionPerformed (ae);}}); // Action Listener Added   

} has been implemented:

  public void submitActionPerformed (ActionEvent ae) {// body}   

In this method, I do not need to apply the ActionListener. Why I?

Also, please explain what is the label as code line 1 .

Please clearly state two snippets

You have technically implemented the Action Manager When you are called addActionListener :

  submit.addActionListener (New Action Listener) {Public Zero Action Action (Action Avenue) {submitActionPerformed (ae) ;}});   

You have made an example of one, or a class that applies without the ActionListener name.

In other words, the snippet above essentially seems like we did this:

  class MyActionListener applies ActionListener {public zero action action (ActionEvent ae) {SubmitActionPerformed (ae); }} Submit.addActionListener (New MyActionListener ());   

For your example, the anonymous class just calls one of your member methods, submitActionPerformed . In this way, your method may have a slightly more descriptive name than actionPerformed , and it makes it even more useful in your class than the ActionListener.

Comments