• 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

Singelton pattern in GUI

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

After selecting mode my program displays a frame (extends JFrame) with the menu bar. When user selects any option (eg Search by Name). control in Program goes to another file(without extends JFrame) that has different gui components(including JPanel(s) but not JFrame) and other relevant code. Now I remove any previous existing panel and display this new panel(s) inthe old frame with same menu bar. ofcourse used Singelton for this.

I read in some forums on net that singelton in GUI does not work good in some operating systems when have many clients. Another says Singelton pattern is anti pattern.

Can you, my fellows, please give your opinion about this or any better design.

Thanks! in Advance
Best Regards!
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tahir,

singleton is nothing else by a unique object instance. Each time you will launch a new Client the VM will create a new instance for the new launch, this not going to be shared between the two clients. As i understood you have a main frame and you remove and place panels according to the user's action. Speaking for design point of view it would have been better if you have used a Cardlayout and according to the user's action display the apropriate card.

Singleton will behave just fine like other clasess as long as you manipulate its content thread safe, all operations done on Swing code to be performend by the event dispatch thread.

Hope i helped!
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tahir,

I agree with Nicolas on this one: if you decide to switch panels in your main window, you should use the CardLayout, because that layout is designed to do what you want. If you use your own custom system (singleton pattern or not), it conflicts with this principle (from instructions.html):

Use of functionality provided by the core Java classes will be preferred to your own implementation of that functionality, unless there is a specific advantage to providing your own implementation.



Kind regards,
Roel
 
Tahir Abbas
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks you very much for this useful information.
reply
    Bookmark Topic Watch Topic
  • New Topic