Re: Creating a simple visual user interface
JK wrote:
OTOH there's that aphorism, "code generation is a design smell". (From
here: http://c2.com/cgi/wiki?CodeGenerationIsaDesignSmell )
The upshot is: what's the point of even *having* the generated classes,
if the "form" file contains everything necessary to build the UI?
Well, in fact the "form" file won't have everything. It has the GUI
component layout (or something like that) only. You still edit the code
and customize it (hopefully just with Interfaces and addListener
methods). The GUI tool just does the grunt work of generating an
attractive, robust component layout.
In theory anyway, I haven't tried it for large projects.
All NetBeans GUI classes (that I've used) look like this:
public class YourNameHere extends JFrame {
public YourNameHere() {
initComponents();
// .. add more here
}
private initComponents() {
// machine generated code here
}
//.. more stuff, most of it added by you
// machine generated private fields here
private JComponent someField;
}
And that's it. When the JFrame is re-generated, only the machine
generated sections are touched. The rest of the class that you have
edited remains unchanged. This allows you to switch between editing
code and using the GUI editor freely, with out issue, as long as you
don't touch the machine generated parts.
In practice, this has worked really well for me, and I think it would be
very easy to adapt to almost any sane framework or design. You would
have problems I think if the design called for exceptionally
heavyweight, complicated GUI objects that were also subject to constant
wholesale revision.
If you have some specific instance or complaint that you'd like me to
try out, if it's not too complicated, I'll give it a shot and report
back with the results (before/after code, etc). I'd be interested to
see myself how it works with more sophisticated stuff that what I've
done with it.