Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

XUI: Finally, a Java GUI Framework You Can Love : Page 3

One of the banes of Java GUI development is in the clean separation of GUI definition and control and business logic. Enter XUI, a new framework for Java that has the ambitious aim of not just solving this problem but of making it easy.


advertisement
Tying It All Together
When you use the XUI editor to create a project, it creates a directory for you containing subdirectories with your source, your compiled classes, your pages, and the XUI runtimes that are needed to execute your app. A copy of this directory is available in the download.

A very important file called startup.properties is found in the properties directory. There is no way to edit that in the GUI at the moment, so you have to do it by hand. This allows you to set up how your GUI will appear (size, start location, etc.) as well as whether it will appear as a 'normal' window (with titlebar, etc., as in Figure 4) or a windowless screen. The property setting is a little strange. If you want to have a window, you need to set it to UseWindow=False (the default is True). This is probably a bug in the framework, so your experience may differ.

The other important things to note in the sample app are the Startup package and class, com.devx.tax and Welcome, respectively. Welcome instructs XUI to start with the form defined as Welcome.xml and use the Welcome.class as code-behind. XUI creates a batch file for you from which you can run your application. If you have any trouble with this, change its name from start.bat to something else (I use runapp.bat) and make sure your paths are all set correctly to point to the XUI jars.

This batch file contains the following commands:

java -classpath .;.\lib\XuiCoreSwing.jar;.\classes;.\resources;.\pages; net.xoetrope.swing.XApplet startup.properties pause

As you can see, it takes startup.properties as a parameter, and from there it determines the first file to load. Multiple form applications are obviously possible, and the XUI core classes handle navigation between them. Check the documentation on XProjectManager (the XUI class that handles how all your forms knit together for workflow and navigation) for more details.

Other Goodies with XUI
XUI has a lot of stuff to offer that goes beyond the scope of this article, so check out the Sourceforge site for more details. Some of the more interesting aspects include:
  • Data Model: This is an in-memory persistence layer between the XML defining the GUI and the Java handling the logic. It can be used to store state of items between dialogs, or can automatically be serialized to disk as an XML representation of your data. All data is keyed according to a text address such as taxes/firstName.
  • NetBeans Editor: There is a version of the XUI available that integrates with NetBeans, making development and debugging of your code a lot easier.
  • Navigation: Through the XProjectManager class you can navigate around all your forms.
  • Styles: The styles associated with your controls and forms are also externalized as XML files. Take a look in your resources directory and you'll see the styles used in the making of this application.
XUI isn't perfect. It still has some bugs, and it isn't the most user-friendly API to get up and running with. In addition, the documentation on the Web site is a work in progress and will take you some time to get your head around. However, from a design point of view, XUI is a major step in the right direction in properly architecting your Java GUI applications. It makes the separation of GUI logic from business logic, not just easy but natural—and it does it automatically for you.

It is for this reason that it makes a nice alternative, or indeed a nice complement to some of the better known XML-based GUI frameworks for Java such as Luxor-XUL and SWT. It has an advantage over both of these in that it is incredibly lightweight and it comes with the support structures to automate running the GUIs (as outlined above) built in. If you are (or will be) doing GUI in Java, you'll certainly want to keep an eye on this project as it matures.



Laurence Moroney is a freelance enterprise architect who specializes in designing and implementing service-oriented applications and environments using .NET, J2EE, or (preferably) both. He has authored books on .NET and Web services security, and more than 30 professional articles. A former Wall Street architect, and security analyst, he also dabbles in journalism, reporting for professional sports. You can find his blog at http://www.philotic.com/blog.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap