• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Anonymous inner classes for event listeners

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I want to know how often do people separate their event listeners to be inner class or public class?

I'm thinking anonymous inner classes would make junior programmers harder to read for clarity sake. If public classes, then most likely I need to pass the necessary variables to the new class. If inner classes, then I need to make the necessary variables as instance variables.
 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ordinarily I would use anonymous inner classes for the event listeners. For SCJD I just used seperate classes as this seems so much easier for a junior programmer to understand.

Not sure why your event listeners need to be public though? All mine are private classes in the class where they are used. The variables required by these inner classes are setup as instance variables in the main class for use by the inner classes as you suggested
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kevin. The reason I want put listeners as public classes is that there are multiple places to do the same thing like disposing windows, or checking text field length.
 
reply
    Bookmark Topic Watch Topic
  • New Topic