Delphi and VB Developers, You Too Can Build Java GUIs

wo years ago, the Swiss business software maker Abacus Research AG decided to port its complete product line from Borland’s Delphi to Java/Swing. The Abacus Delphi development team faced the unenviable task of rewriting hundreds of GUI applications in Swing without the aid of tools like Delphi or Visual Basic. When Abacus Research looked at the few GUI builders available at the time, it found three basic disadvantages:

  1. Abacus developers found them complicated, in part because they required Swing knowledge in order to create an application. The developers wanted to create forms within minutes without Swing knowledge.
  2. The tools lacked XY layout managers and the canvas-style interface that VB offered.
  3. Abacus Research needed the ability to separate the UI forms from the business logic, which the third-party tools that it reviewed did not provide.

With so many applications to rewrite, time constraints, and a large number of seasoned GUI developers who had little experience in Swing, Abacus Research developed a plan to bridge the gap: writing its own Java tool that functioned like Delphi and Visual Basic and making it available to all developers under the GNU General Public License. Its solution would allow the developer to more easily separate the UI design from the rest of the application logic.

Thus was born the Abacus GUI builder (AbaGUIBuilder), an open-source Java GUI builder designed to provide GUI developers with an easy and rapid Java/Swing development tool. Abacus realized early that its application developers do their best work when they can concentrate on the business logic and UI, instead of the technical details of Swing. Thus, its immediate goal became the implementation of a WYSIWYG tool powerful enough to handle any user interface requirement.

 
Figure 1. The AbaGUIBuilder Interface

Abacus’s first decision was to provide an XY layout with object anchoring, similar to Delphi or VB (see Figure 1). The XY layout transforms the JFrame into a canvas where a developer can drop Swing objects from the class palette. In contrast, most Java layouts managers dynamically render screens according to the resolution of the display.

Next, Abacus determined that the AbaGUIBuilder would output jar files instead of “usable or reusable” Java code. It manufactures and compiles an application jar that hides the UI implementation details. In order to run the application jar, a wrapper program with an AbaRenderer object loads the jar and renders it on your desktop. Other noteworthy features include the abilities to create JFreeChart objects visually, import third-party classes into the class palette, and create database applications using JDBC data sources and DB-aware components.

The following sections use a sample application to walk you through an AbaGUIBuilder build, from creating the application and running it to adding event handlers and writing your own wrapper.

Editor’s Note: The author, Mario Castillo, is a member of the Open Abacus team, which develops the AbaGUIBuilder tool. We have selected this article for publication because we believe it to have objective technical merit.

The First AbaGUIBuilder Demo: The Person Application

 
Figure 2. Quick Person Application

The AbaGUIBuilder can also provide you with instant feedback about your GUI application’s look and feel as you build it. Its IDE Rendering mode helps you put an application together in just a few minutes (see Figure 2 for a sample application called Person) and render it within the GUI to see exactly how the application will look like once you run the jar (see Figure 3 for a rendering of Person).

As you can see, the Person application has two panels with multiple JTextFields and JLabels, and a pair of buttons. You can build this application in a few minutes using AbaGUIBuilder.

 
Figure 3. IDE Rendering

After you “Save and Compile” a form, the builder stores the project definition in a .proj file. It then creates an application jar and a project declaration file (proj.decl). The declaration file has Java code fragments with object declarations and an access method with all the visual objects on the form, which you can use for development later.

Running the Person Application

To run an application jar, you need to write a small Java program that instantiates an AbaRenderer object. The object loads and renders the application jar. Abacus recommends initially using the runproz script and the wrapper program in the AbaGUIBuilder’s samples directory until you get familiar with the rendering process (see Figure 4).

 
Figure 4. Rendering the Application Jar

The runproz script adds all the required jars to the classpath and executes the sample wrapper exec.java. To test your application jar, copy it into the samples directory and run it with the following runproz script:

runproz AbaGUIBuilder-1.7samplesperson.jar
 
Figure 5. Adding Option Dialog to an Event Handler

The execute.java wrapper in turn instantiates an AbaRenderer object, loads the application jar, and runs the application (see Listing 1).

Adding Object Event Handlers

 
Figure 6. Executing the Event Handler

Adding code to events is a critical phase to any GUI application project, and the AbaGUIBuilder makes adding event handlers a snap. Just select the object from the canvas, choose the event from the event dropdown, and write the Java code in the Event Source and Object panel. The builder hides the listener code and presents event handling in a paradigm similar to Visual Basic or Delphi. Internally, the IDE manufactures a listener class that’s added to the visual object at rendering time.

If you want to add a confirmation dialog to exit the application, simply add an instance of the JOptionPane dialog to the actionPerformed event on JButton1. The event code in Figure 5 activates the JOptionPane dialog when the user clicks on the “Cancel” button.

Now, when the user clicks on the Cancel button, the JOption dialog pops up and queries the user for confirmation (see Figure 6).

Writing Your Own Wrapper Program

Typically, you write your own rendering program if you wish to separate the UI from the application, or when you want to have direct control of the UI components. For example, if you wanted to use a third-party library that required a specific listener, you could add this listener in your wrapper code and update the UI components from the wrapper.

If you decide to write your own wrapper, you must take the following steps:

  1. Create an AbaRenderer object.
  2. Execute its Load() method, which returns “true” if the application jar has been loaded.
  3. Execute the RenderInterface() method in order to render the application:
    	    String jarname = "\abaguibuilder-1.7\samples\person.jar";	    m_AbaRenderer = new AbaRenderer(jarname, true , null);  	         boolean bTestLoad = m_AbaRenderer.load();        m_AbaRenderer.renderInterface();

Another reason to write your own wrapper is to initialize the visual controls on the form with code in the wrapper program. For example, to load the combo box with items before it is rendered onscreen (as in Listing 2), you can paste the object definitions and the getReferences() function into your wrapper code.

Separating the UI from the business logic is an important topic to consider when designing a visual application. Although beyond the scope of this article, be sure to keep this in mind when using the AbaGUIBuilder.

Delphi and VB Developers, This One’s for You

The AbaGUIBuilder has the unique charter of it focusing exclusively on the Delphi and VB developer moving to Java/Swing. As a result, it’s not for everyone–it provides the greatest benefit to those application developers seeking an easy front-end development tool similar to VB or Delphi. Abacus Research simplified the IDE with a true WYSIWYG environment, removed complicated layout managers, and hid UI implementation details from the developer.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Related Posts