The complete source code of the following quickstart example is contained in the folder org/gui4j/doc/examples/quickstart in the zip file examples-src.zip
The example can be run with the command:
java -cp gui4j.jar;examples.jar org.gui4j.doc.examples.quickstart.MainOne of the first things you must do is to initialize gui4j. For initialization a properties file with all possible components is necessary. The syntax is
xmlTagName = gui4jFactoryClassName
The components are initialized lazy on first use. The file gui4jComponents.properties contains the current list of all supported components.
The following lines initialize gui4j with an unlimited number of worker threads, with validation of xml files and without detailed logging of method calls:
URL url = Main.class.getResource("/org/gui4j/doc/examples/quickstart/gui4jComponents.properties");
int numberOfWorkerThreads = -1;
boolean validateXML = true;
boolean logInvoke = false;
Gui4j gui4j = Gui4jFactory.createGui4j(validateXML, logInvoke, numberOfWorkerThreads, url);The gui4j instance contains factory methods for creating views and dialogs. To create a view, a xml resource file is necessary and a controller handling the method calls.
String resourceName = "main.xml"; String title = "My first application"; boolean readOnlyMode = false; Gui4jController controller = this; Gui4jView gui4jView = gui4j.createView(resourceName, controller, title, readOnlyMode);
A controller must implement the interface Gui4jController
The resource file main.xml must contain a component definition with the special guiId TOP. This component is the root of the window containing all other components in a tree structure. There is also another special identifier with the name TOP refering to an optional menu.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE View SYSTEM "view.dtd">
<View>
<borderLayout guiId="TOP">
<placeBl anchor="center">
<label text="'My first application'"/>
</placeBl>
</borderLayout>
</View>