devdaily home | java | perl | unix | directory | weblog

up previous next contents index
Next: The RCX motors Up: Getting started with Lego Previous: Running the program on   Contents   Index

A second "Hello, world" program

If everything went well for you that first time, you may want to try a second program just to get in the groove, because this is a process you'll go through again and again.

This time, let's a little more excitement to the program, including finding a way to get the "world" word on the LCD, and a little sound for special effect. I'll call this class HelloWorld2, which is shown here in the HelloWorld.java file:


import josx.platform.rcx.*;

public class HelloWorld2
{
  public static void main (String[] args)
  throws Exception
  {
     LCD.clear();
     TextLCD.print ("hello");
     Thread.sleep(2000);
     TextLCD.print ("world");
     Thread.sleep(2000);
  }
}

This program is also very simple. Here, we write the word "hello" out to the LCD as before, but then we do something a little different. Basically, we tell the brick to sleep for two seconds (more specifically 2,000 milliseconds), then print the word "world" to the LCD display, then sleep for another two seconds, at which point the program ends.

Again, this is a pretty simple program, but that's what we're trying to do here - write a few simple programs, and establish a rhythm to your software development.

At this point you should be able to compile this program, transmit it to the RCX, and then run it from there.

If you are interested in testing this program, you can download it here as HelloWorld2.java.


up previous next contents index
Next: The RCX motors Up: Getting started with Lego Previous: Running the program on   Contents   Index