• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

GUI Design

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm struggling with the appearance of the code in the class for my GUI client that extends JFrame. In general, the methods of the class handle building text fields, buttons, labels, etc. and get the values to display from a controller class. However, at least half of the file is composed of about 12 inner classes that implement some sort of listener. I've written listeners to set default buttons based on focus, activate/deactivate buttons based on what is selected, and all kinds of other little things that make the GUI experience a little smoother. The inner listener classes need access to the member variables of the enclosing class to be able to manipulate them as described, so I can't think of any other way to make this work and to not make my code look (in my opinion) very ugly. I've never had to rely on such overuse of inner classes in any other application I've ever written.

Is this just what you have to do with swing, or is there a cleaner way? Maybe making the target member variables static protected, extending my ClientWindow class and implementing the listener interface... then I could create separate class files for each listener, but that seems like a sloppy work-around in itself.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would make heavy use of Actions. Have an action for all actions a user will make, ie. search, delete, create etc. Inside the action you should have the call to the delegate and backend, and also any error pop up dialogs. If the action leads to another pop up dialog. Contain the dialog as an inner class of the action class.

That way your code will look lots cleaner
 
reply
    Bookmark Topic Watch Topic
  • New Topic