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

Strange GUI Coding

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

I downloaded Eclipe's Visual Editor today to see if it was any good. While testing it though I noticed something I found strange. Here is a code snippet



Anyone else code GUI's this way?


GenRocket - Experts at Building Test Data
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
besides some examples from sun java tutorial (and some text books too) i never saw swing code for real; so i wonder if eclipe's code is recommended.

Is it really that bad? Does other IDEs code swing better? or is it a common problem to IDEs generation code?

do you recommend hand code swing instead?

TiA


java amateur
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I prefer to handcode my GUIs in Java - I like the control that gives me. In my limited experience, GUI-editors almost invariably create much more complicated code, which makes it harder to maintain the GUI (which is the main work in software development!).


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
(...) to maintain the GUI (which is the main work in software development!).
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by miguel lisboa:


Maintenance in general, I meant, not maintaining GUIs...
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i kept GUI in order to not change your words, but i understood you refered to code in general

anyway now that i think of it, one does this program, then passes another 5 or so years making updates to it or fixing bugs or both ...
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by miguel lisboa:

anyway now that i think of it, one does this program, then passes another 5 or so years making updates to it or fixing bugs or both ...


Exactly! If a program gets used, people will find things that can (and should) be improved. People will get ideas for new requirements. They will want to use it for new problems. Other people will want to use it, but they will have slightly different requirements. Etc. pp.

The very most important property of a software system is its maintainability. Whole companies go bankrupt because they don't consider this important reality.
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
The few times I developed a Swing client I started with Netbeans or IBMs Visual Editor which is now part of Eclipse.
I allways ended up with hand-coding. Took some useful ideas how to strucutre the code from examples on JGoodies.com (Forms demo) as I am using their (or better his?) Look & Feels and Layout manager anyway.
The Gui subproject at my current main customer uses self written code generation from xml files to build guis. Have some doubt, if they are not perhaps ending in lack of flexibility/messy maintainabiltity problems with this approach, though.
Now Scott Delap new book on sourcebeat should contain some expedient guidelines to follow.
[ May 01, 2005: Message edited by: Axel Janssen ]
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
If you're referring to this "lazy initialization" method, then yes I code my GUIs that way. It makes it easy for me to figure out where the initialization code goes for a particular component. If I want to know why my "Ok" button looks/behaves the way it does, I look for the getOkButton() method. I'm not saying it's the best way in the world, but it has worked well for me and makes maintenance quite easy.


James Carman, President<br />Carman Consulting, Inc.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by James Carman:
If you're referring to this "lazy initialization" method, then yes I code my GUIs that way. It makes it easy for me to figure out where the initialization code goes for a particular component. If I want to know why my "Ok" button looks/behaves the way it does, I look for the getOkButton() method. I'm not saying it's the best way in the world, but it has worked well for me and makes maintenance quite easy.


What we do in such cases is have a createContent method, which might delegate to a createOkButton method. Those methods are only called exactly once. Most often simply is no need for the increased complexity of lazy initialization, in my experience.
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
I don't know about the complexity of lazy initialization, but as I said I'm not saying it's the best way. It just works for me. I actually don't do much of that type of coding anymore. I wrote a class which allows me to specify my GUIs using an XML document (looks like HTML tables) using GridBagLayout. It even supports binding event listeners to the components. The event listeners usually just call methods on a controller object. This binding is all done using OGNL. That is how I usually code these days. It seems to be much simpler.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange GUI Coding