• Post Reply Bookmark Topic Watch Topic
  • New Topic

Anonymous Inner Class Query  RSS feed

 
ravisha andar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have a basic query

Whwn we say

button.addActionListener(new ActionListener()
{
public void actionPerfored(ActionEvent e)
{// do something.
}
}
);

WHere exactly are we saying the actionPerformed method is to be called

Please help me understand this.

Thanks
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What that code is doing is adding the new ActionListener to a list maintained by the button. Then, when the button is activated, it will call actionPerformed on every object in the list.
 
ravisha andar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks

How is the actionPerformed() method called , since we are not calling it anywhere
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're not calling it directly, but the AWT / Swing code will call it when you press the button.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!