J2SE

Graphical User Interface (GUI) problem in Java

The problems

After a little experience, it isn’t difficult to build a Graphical User Interface (GUI) in Java, but it is hard to get something that is easy to write and maintain, and looks good.
Many styles of GUI programming simply don’t scale well.

Separation of concerns

BAD: Mix logic and interface.
This is a typical style for small student programs. The code to perform the action of a button is in the button’s action listener. This does NOT scale well as programs get bigger.
GOOD: Separate GUI from logic.
As programs grow larger, it’s essential to separate the GUI interface processing from the logic. This is easy to do by putting the interface and logic in separate classes. Some GUI generators below help accomplish this.

Some GUI programming alternatives

1.)  Use Drag and Drop GUI editors. Many IDEs (NetBeans, Eclipse (only SWT), JBuilder, ...) have GUI editors and there are also numerous standalone products. They don’t always enforce separation of interface and logic, but it’s usually easy to do. I’ve used NetBeans with good results.
The new NetBeans Matisse project looks very promising.

2.)  Alternatives to Swing and AWT.
You don’t have to use the Java GUI libraries to build your GUI. There are alternatives.

-  SWT - IBM’s alternative to Swing. An interesting discussion can be found at www.hacknot.info/hacknot/action/showEntry?eid=74.

-  Bouy - (buoy.sourceforge.net/) - A public domain alternative. This looks nice, but I haven’t taken the time to try it out yet. They claim it’s simpler with better layouts.

3.)  Use Flash or JavaScript+HTML for the GUI.
Why should your interface be in Java? You can use existing GUI technologies like Flash or JavaScript+HTML (check out Sun’s LiveConnect, which should already be installed with your version of Java) to interact with your Java program. Apparently this sounds better in principle that in practice. I’m not away of many users of this approach.

4.)  Describe the GUI in some other language (eg, XML).
This approach is described below in the XUL (XML User interface Language) philosophy.

Best regards,

Yupi Sugianto,S.Kom



Related posts

Leave a Comment