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
, 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;
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 naturaland 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.