HelloWorld

This page has been updated on the 21 July 2010.
Information validated on 2.4.0 framework.

Objective

We are going to develop a little application which prints out “helloworld” in the log and on the screen.

Create a new “graphical interface component”

The purpose of the helloworld component is to understand the architecture of a project and the use of another component.
This will be done in several steps :

  • STEP 1 : Architecture of the project
  • STEP 2 : Use of Components

Preliminary step

Create a user interface component called helloWorld with package name : com.training.helloWorld

Step 1 : Architecture

Project structure

A project made in the SDK has 3 main parts:

  • the JCPN file
  • the MDU file
  • the src folder

To learn more about project structure, please read Create and import a project

The JCPN file

The JCPN file is an XML file which describes a component.

To learn more about JCPN, please read The JCPN File

The MDU file

The MDU file is an XML file which describes the graphical interface of a component.

To learn more about MDU, please read The MDU File

Step 2 : Use of components

  • In the JCPN file Add Required interface : Debug
  • Open the Initial file.
  • In the start() method of the Initial class retrieve the Debug instance.
  Debug dbg = Component.getInstance().getDebug();
  MuiCommand muiCommand = Component.getInstance().getMuiCommand();
  if (muiCommand != null)
    muiCommand.register(new BuffRef("com.training.helloworld"));

Now that we have the instance, we need to call the init() method if it takes parameters.
The init() method defines the debug level we will see.

    [...]
    dbg.init(0); // initialize debug to see all log  

And then we can use the debug methods.

    [...]
    dbg.print("helloworld");
    dbg.debug("helloworld");
    dbg.warn("helloworld");
    dbg.error("helloworld");	

After that you can launch the simulation with helloworld inside and then you can see the following lines in the console :

2010-XX-XX XX:XX:XX  L[j$com/training/helloWorld$0] helloworld
2010-XX-XX XX:XX:XX  L[j$com/training/helloWorld$0] helloworld
2010-XX-XX XX:XX:XX  L[j$com/training/helloWorld$0] helloworld
2010-XX-XX XX:XX:XX  L[j$com/training/helloWorld$0] helloworld

Each call prints out the text in different colors and adds the package name at the beginning.