Getting started

From JAXXWiki

Contents

Basic concepts

The best way to think of JAXX is as a simple programming language. You will write source code files (.jaxx files) and compile them using the JAXX compiler, jaxxc. Each .jaxx file compiles into an ordinary Java class, which you can then use just as you would any other Java class.

Working with jaxxc is intentionally very similar to working with javac. Just as you normally interact with javac from the command line only, without having to call any of its internal APIs, you will likewise normally interact with jaxxc from the command line only. Most users will never need to concern themselves with any of JAXX's internal APIs.

Installation

If you don't already have JAXX installed, follow the installation instructions to set it up.

A simple JAXX file

Full documentation on .jaxx files can be found at JAXX files.

A .jaxx file is an XML file that (typically) describes the layout and behavior of a component tree, often a frame or dialog. Most of the tags in a JAXX file are the names of classes; these are referred to as class tags and mean "create an instance of this class".

The very 2000 simple JAXX file:

<Application title='Test'>
  <JLabel text='This is a simple JAXX file'/>
</Application>

creates an Application (a subclass of javax.swing.JFrame) and inserts a JLabel into it. When compiled and run, it looks like this:

Image:Test-screenshot.gif

Compiling and running the example

To compile and run this example, create a file named Test.jaxx and paste in the source code above. The compile it using jaxxc and run it using java:

c:\jaxx\examples> jaxxc Test.jaxx
c:\jaxx\examples> java -classpath .;c:\jaxx\lib\jaxx-runtime.jar Test

(Naturally, you must adjust these commands as appropriate for your directories and operating system.)

The first command above assumes that you are in the directory containing the Test.jaxx file. Compiling it as shown will produce a class file named Test.class in the current directory, and because you were in the same directory as the JAXX file the resulting class will not be placed in a package (its fully-qualified name is just Test).

At this point Test is a perfectly ordinary Java class.

JAXX automatically gives Applications a main() method, so the only special requirement to run the class is that jaxx-runtime.jar be in the classpath.

Class tags

Full documentation on class tags can be found at Class tags.

JAXX's class tags are a sharp departure from how most XML user interface languages (XULs) work. Most XULs support a pre-defined set of tags which map to built-in components. To create a component which is not part of the pre-defined tag set (for instance a custom subclass of one of the built-in types), you must generally call API hooks to add support for a new tag before the file can be compiled.

JAXX tags, on the other hand, are simply class names (which can optionally include package names). JAXX will load the specified class and introspect it to automatically identify the properties and events it supports; you do not need to do anything special to enable support for the class. You can use the JAXX API to enable custom support for a class if needed, but most of the time you can just rely on JAXX to analyze the class and figure out how best to utilize it.

Scripting

Full documentation on scripting can be found at Scripting.

JAXX uses Java as its 'scripting' language. You can use the <script> tag to embed Java code in a JAXX file; this Java code can contain statements as well as field, method, constructor, and inner class declarations. Statements are run in the class' constructor, while field, method, constructor, and inner class declarations behave as if declared in the class' body. This means you can use <script> tags to declare new methods and fields or even override methods found in a superclass.

In addition to being explicitly declared in a <script> tag, Java code can appear in several other contexts such as data binding expressions or event handlers.

Despite being called a 'script', Java code appearing in a JAXX file is fully compiled and runs as fast as any other Java code.

Example JAXX files

The Examples page contains examples which showcase complete, working JAXX programs.