• 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

Design help - Need help in "static" implementation with Swing application

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

I am new to event based code. I am writing a Swing application from scratch. I have one main Swing class for displaying UI components and a Listner class implementing ActionListener interface.

I have made all components related to ParentGUIWindow as "static" because the ParentWindow will be displayed at the start of application. There wont be any multiple instances of different components. Hence thought of keeping them static.

Now, problem is as all of my GUI components are static , so i am forced to make the listener object static as well. I want to know, will it be fine if I make reference of listener ( object of the class implementing ActionListner) as static in SwingMain class ? Is there any harm to have a static listener object for entire application or should i go with "this" implementation done with non static components?

Please find code below:




I want to design and code in the most efficient manner. Please help me to do a good design.

Thanks in advance,
Kacee
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will need a different Listener for each button, surely.
So make the createButton method return the button, and pass the Listener as a parameter. Have a look through a book which shows you how to create Listeners as anonymous classes, eg Deitel or Horstmann and Cornell, etc. I haven't written about that for some time, but I still think I was correct in my rule of thumb here and here. See whether those posts help, and the older links therein.
You will end up with something like this . . . once you have corrected all my spelling errors.

I don't like having all your members static.
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic