Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strange GUI Coding

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!).
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(...) to maintain the GUI (which is the main work in software development!).
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by miguel lisboa:


Maintenance in general, I meant, not maintaining GUIs...
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic