Sinelabore Homepage

Java Code Generation#

To generate Java code, call the code generator with the command line flag -l java.

The generator creates one Java class that implements the complete state machine. This keeps your Java project compact and avoids many helper classes. If required, an optional base class can be specified in the config file. The package (Namespace=...) can also be defined there. Events that can be sent to the machine are defined in a public enumeration.

The following example shows how to use generated code together with a GUI class based on a simple Swing application. Each time a button is pressed, an event is sent to the state machine, which writes entry/exit code of the current state to the text window.

Class SMBase.java serves as a bridge between Java GUI code and generated state machine code.

Java GUI example

The state machine that realizes the behavior of button presses looks like this:

Java example state machine

The complete Apache NetBeans project file can be downloaded here.

More information is available in the manual section Generating Java Code.