Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

multiple action listeners .setActionCommand Vs. addActionListener(new comboListListener())

 
Greenhorn
Posts: 21
Mac OS X MySQL Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All

I have been working on a form that will have multiple buttons and comboboxes. I have worked out two ways to achieve the functionality of multiple listeners for multiple sources, or one listener per source might be a better way of putting it. And I am wondering about the performance / memory usage of each method.

My question is a multipart question.

which method will use more resources as the number of sources grows?

would there be a performance hit for either method?

would either method present a security hazard?

does method one seriously break OOP?

TIA

Method One: use one common listener and the setActionCommand differentiate between sources.



Method Two: use actionListener classes for each object that needs to be heard

 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

bob von ilten wrote:I have been working on a form that will have multiple buttons and comboboxes. I have worked out two ways to achieve the functionality of multiple listeners for multiple sources, or one listener per source might be a better way of putting it. And I am wondering about the performance / memory usage of each method.


This sounds to me like a very specific question; so, if you don't mind, I'm going to move it to the relevant forum.

However, I would say this: Don't worry about performance until you KNOW it's an issue; concentrate instead on getting the design right. Chances are, the latter will get you close to the first anyway.

Winston
 
Rancher
Posts: 3272
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use method 2, it is the better design. The creation of one extra class will have no affect that you will be able to measure.

As a general rule, the only time you should use the action command is to handle common functionality. For example maybe you are creating a calculation and you want buttons to enter the digits 0-9. So in this case you can use a common ActionListener and then just use the getActionCommand() method to determine which digit to add to your calculator display. This type of code doesn't require nested if/else or case statements.

 
bob von ilten
Greenhorn
Posts: 21
Mac OS X MySQL Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks I appreciate the feed back. I will move forward with the individual class design. As to moving it that is fine with me, the main reason I posted it in the beginning forums was that is where I seem to be living lately :-) I also had a rough time finding a simple code example of dealing with multiple sources and single listeners per source. I thought the code example might help some other beginners.

But either way - Thanks Again
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic