Exercise 6 - Code generation (Java)
In this exercise we will create a generator model and generate Java code from our example model. The generated
Java code is then used in a simple UI application that visualises the light bulb.
Creating a new code generator model
- Create a new code generator model via New → File → Code Generator Model.
- Select the statechart you want to generate code for (Light.sct).
- Select the YAKINDU Java Code Generator from the drop-down list at the top.
- Check which features are available to tailor the code generation process (try [Ctrl]+[Space]).
- Create a RuntimeService and a TimerService.
Using the generated code
Open the LightControllerDemo.java class and make yourself familiar with the code. To use the generated Java
code, implement the setupStatemachine() method.
- Create a new instance of the LightStatemachine.
- Add a TimerService and add the state machine to the RuntimeService.
- Connect the lightSwitch button to the state machine (ActionListener). When the light switch
is clicked, the down event should be raised.
- Connect the setBrightness callback operation to the light object.