• 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

Swing:listeners

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

i am new to java swing programming.

i am making small aplication in swing.

i am making listener classes for components mounted on frame.

my query is that can i make seperate listener classes & put them
in one package so that they are seperated from view classes (GUI Part)
which are preent in other package
or
make this listener classes as innner classes in classes which represent view part of an application.

which is standard way?

Please Help.

Thanks in advance.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> which is standard way?

there is no 'standard' way.

it depends entirely on the application
e.g. a 'Cancel' button, which has a single purpose, is ideally linked to an inner class listener,
whereas the buttons of (say) a minesweeper game would probaly share a class, using getSource()
to identify the button
 
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.

I think you should use them as inner classes, because this is one of its purporses.
Normally it is a specialized code, i.e., you won't use it in other places, so you use it as inner class.

http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html
http://www.javaworld.com/javaworld/javaqa/2000-03/02-qa-innerclass.html?page=1
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leandro Coutinho wrote:I think you should use them as inner classes, because this is one of its purporses.
Normally it is a specialized code, i.e., you won't use it in other places, so you use it as inner class.


As noted in the post above you, this is fine for small apps, but if you start to develop large and complex apps, you may find that this doesn't scale well, that you need to separate out the control portion from the view portion of the code.
 
anuj thite
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

pete stein wrote:

Leandro Coutinho wrote:I think you should use them as inner classes, because this is one of its purporses.
Normally it is a specialized code, i.e., you won't use it in other places, so you use it as inner class.


As noted in the post above you, this is fine for small apps, but if you start to develop large and complex apps, you may find that this doesn't scale well, that you need to separate out the control portion from the view portion of the code.




Hi,

thanks alot for your suggestion.

but for seperating view portion from control portion, i have to make two separate packages.
1. one for classes related to view part of an application.
2. other for listener classes.

so for accessing listener class in view portion, i have to make it public.

so is it a Standard way to expose listener classes to outside according to application design point of view???





 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I usually prefer to do it this way.
1) If the action is going to be invoked only from one source, have an anonymous inner class.
2) If the action is going to be shared (e.g. in a popup menu, a button and say menu bar) I prefer to subclass AbstractAction and share it between all the action sources.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic