Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2008

Tip: Looking for answers? Try searching our database.

Good design and practice of gui code

Thread view: 
jasoncorbett@gmail.com - 03 Jan 2008 19:34 GMT
I've mostly programmed backend servers, and enjoy Java a great deal.
I've gotten to a point where I have to write some GUI for my backend
machines.  I dislike most gui code I've seen (not that much) because
it appears to me to be a complete mess.  I used a gui designer and it
produced a huge java file that I would be embarrassed to put my name
on.

Is their a good method to writing nicely coded gui's.  I'm not so
concerned with what the ui should look like (there is a lot of good
info about that), mostly about how to design and code a gui in a good
manner.

I've read a lot on MVC, but I rarely see code that reflects what I
think good MVC should be.  Is this a common problem, am I going about
this all wrong?

Jason
Roedy Green - 03 Jan 2008 22:18 GMT
> I dislike most gui code I've seen (not that much) because
>it appears to me to be a complete mess

When I first saw GUI code, for a prototype MacIntosh on the Lisa, I
said, "You have got to be kidding.  Nobody is going to go to all this
fuss for a simple app.  I was wrong."

It has not improved that much.

Some things you can do.  

1. Subclass components to put in all your standard tweakings. That way
you can change your "style" in one place and reduce the clutter.  We
need something the equivalent of CSS style sheets for Java GUIs to
hide the details of layout and look.  That goes much further than just
subclassing.

2. use nested panels.

3. separate the allocation and field attributes from the layout.  Keep
business logic separate from both.

4. make great use of the "extract constant" feature to parameterise
your code with named constants.  It is a lot easier to maintain a
named constant that dig in the code for multiple places to change
something.

5. keep your attribute setting methods is a standard order.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Karsten Lentzsch - 04 Jan 2008 08:57 GMT
> [...]
> Is their a good method to writing nicely coded gui's.  I'm not so
[quoted text clipped - 5 lines]
> think good MVC should be.  Is this a common problem, am I going about
> this all wrong?

I recommend other patterns than MVC. For me MVC is good
as a component pattern, for applications there are better
patterns.

1) As with MVC, separate the domain from the rest.

2) Almost always separate the GUI construction, configuration,
layout, and fine grained events (e.g. mouse over) from the
presentation logic; hence, use an MVP variant or "Presentation Model".
The choice between MVP and "Presentation Model" depends on
the toolkit, associated binding support, etc. For Swing,
I favor to follow the "Presentation Model" pattern, because
several Swing core components already use this pattern.

I provide a free presentation regarding Java desktop patterns
that presents and compares MVC, MVP, and Presentation Model,
see http://www.jgoodies.com/articles/ I also provide a free
binding library that assists in using the Presentation Model
pattern, see http://www.jgoodies.com/downloads/libraries.html

Just as a side note. I recommend to favor flat over nested panels
for editor that are perceived as a single sheet. Nesting in Swing
means loosing layout constraints, grid information, and hence
ends up often in unaligned, arbitrary component positions.

-Karsten


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.