wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Coding your GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Coding your GUI" Watch "Coding your GUI" New topic
Author

Coding your GUI

Jeff Allison
Greenhorn

Joined: Dec 09, 2004
Posts: 20
I have a pretty basic question about coding GUI's; hopefully this is the proper forum in which to ask.

I'm new to Java, although not new to software development. I'm writing a program that will communicate via RS232 to various timing and frequency boxes. The GUI isn't complex, a tabbed window with data getting reported in various fields on each tab. There will be (haven't started this bit yet) input fields for controlling the boxes as well. The question is this: how do you structure the code for your GUI? Do you lump all of the labels, panels, etc, into one big class called "UI?" Or do you break the pieces down into small classes, like one per tabbed panel or something?

The later approach seems more elegant, but at the same time it seems like you'll wind up with a lot of references and classes that don't really buy you anything. Normally you create a class for a well-defined piece of data. Splitting up the UI seems pretty arbitrary.

Thoughts?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Usually what I try and do is keep my UI Panels as modular as possible. So most of my classes will be panel classes. That is to say I will have several classes that extend JPanel. Other than that most things are jumbled together. Otherwise I run into inner-app communication problems between different components.


GenRocket - Experts at Building Test Data
Warren Dew
blacksmith
Ranch Hand

Joined: Mar 04, 2004
Posts: 1332
    
    2
With tabbed panels, I use one class per tab, in addition to an overall class for the interface. If tabs are internally complex, I may create additional classes, but these would be subordinate to the panels.

If you think of it from a user interface design perspective, it makes sense: the things that the user will be paying attention to at one time probably belong in the same class; things that aren't even visible at the same time, such as different tabs in a tabbed pane, probably belong in different classes.

I actually find that breaking down the classes this way is even more intuitive for a UI than for data.
Jeff Allison
Greenhorn

Joined: Dec 09, 2004
Posts: 20
Thanks to Gregg & Warren for the responses. I've been prototyping for a week or so now so my UI code is a complete mess. Now that I've got some idea of what works and what doesn't it's time to step back and organize it properly. I think it makes sense to break things down along panel and/or tabbed pane lines. Not only will that make the code more manageable, it'll give me some flexibility in terms of setting up the UI a little differently for different boxes.

Thanks again.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Coding your GUI