main
print "Hello, World!"
The most simple application that prints "Hello, World!" looks like this:
main
print "Hello, World!"
main is the function where the execution of the program starts. Its body is resolved by indentation, so in this case main contains one statement, namely print "Hello, World!".
The command print prints text to the debugger log. It is useful for debugging, but in a real application we want to draw to the device's screen. The following example prints "Hello, World!" to the screen.
main
System.run application new MyApplication
class MyApplication extends Application
draw to <Canvas c>
c.draw string "Hello, World!" to 0, 0
The first thing we do in main is to create a new application object and run it. The system function System.run application <Application> runs a new application. We give it a new instance of MyApplication as its parameter by saying new MyApplication.
We define a new class, called "MyApplication" by declaring class MyApplication. It extends a system class called Application, which is the base class for applications.
draw to <Canvas c> is a method derived from Application class, that the framework calls when it wants the component to draw itself. <Canvas c> is a parameter for the method, the type of the parameter is system class Canvas, and the name of the parameter is c, or any other name it is given.
The graphics class has a member method called draw string <string> to <position>. It draws a string to the screen. String literals are given in quotes, like "Hello, World!". Position on screen can be given simply as 0, 0 or as any other pair of coordinates.