Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

So, I have a program which has a swing GUI. (Java - duh!) I really, really don't think the way I'm structuring my classes now is good, so I am reorganizing from the ground up to follow best practices.

Classes:

UI - The big daddy. It's intended usage is to first create the containing JFrame, call for the construction of all of the subcomponents of the UI, then add them in a border layout to the JFrame (would it be wise to structure this as a singleton? After all, I don't want two UI's?)

RightPanel, LeftPanel, BottomPanel, TopPanel, CenterPanel. Different panels of UI subcomponents. I have a class for each of these panels.

Menu- The menubar. A seperate class just to keep menu duties seperated from the rest of the UI code.

I'm not quite sure how to structure these, within relation to each other.

A few possible options I have thought about, (just what I've come up with, there is probably a better way to do all of this):

  • Make all classes an inner class of UI. I don't like this option for obvious code bloat reasons.

  • Make each class independent of UI. Possibly even make each class a singleton, since I'd only ever need one UI along with all of it's components.

  • The millions of better ideas that haven't even crossed my mind.

What is a good way to do this? I'm by no means an expert on design patterns yet. I'm still trying to get an exceptionally solid grasp on OOP concenpts.

(Unnecessary additional concerns):

Additionally, I obviously need a way for my program to interact with the UI, updating displayed information on multiple components from one event, and for buttons within different subcomponents to dispatch to a handler, sending data along on it's way and possibly even modifying other UI stuff. If you could devise an efficient way to structure this I'd love you even more

share|improve this question
    
I don't have experience with Java/Swing, but have with C#/WPF/XAML. After some initial suffering, we started to get good results following a simple rule: use your GUI toolkit the way it is supposed to be used. That you can get from documentation, from books about the toolkit, and by taking a look at some opensource code, for example at GitHub. But I would prefer some tutorials or documentation. –  heltonbiker Aug 2 at 22:20
    
@heltonbiker Swing IS java. In other languages, you have just what you said. External GUI toolkits. But because swing is so central to Java, the documentation is more of, 'how to use this' rather than 'what is the best way to use this'. I appreciate the response though. –  HCBPshenanigans Aug 2 at 23:00
    
I'd just as soon get flogged with wet ropes than use Swing again. Are you sure you can't use something more modern and vastly superior, like JSF or JavaFX, or even SWT? –  Robert Harvey Aug 4 at 14:20
    
@RobertHarvey I kept starting to learn JavaFX and just didn't like the way it was set up. Maybe I'll try again one of these days. –  HCBPshenanigans Aug 4 at 16:24
    
Hopefully you've got a really good IDE with a Visual Forms Designer. The Visual Designer should already be doing most of the class organization heavy lifting for you. –  Robert Harvey Aug 4 at 16:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.