Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

need not simple API source  RSS feed

 
jrookie
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in all java tutorials for menu,buttons use listeners as inn classes
like that
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
});
when it makes in external Listener ?
i would like to look at to source code some api
with this
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"jrookie" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

As a quick answer to your question... it makes sense to use anonymouse inner classes as listeners if the listener only applies to the component you are attaching it to. If you have plans for connecting the listener to multiple components, or if you want to make the listener generic and use it again in another context, you need to specify the listener in a separate class.

Thanks! and welcome to the JavaRanch!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!