Following is the complete code sample for the HelloWorld application for a Palm device:
import com.sun.kjava.Button;
import com.sun.kjava.Graphics;
import com.sun.kjava.Spotlet;
/**
* Simple demonstration, "Hello World" program. Note that Spotlet is
* the class that provides callbacks for event handling.
*/
public class HelloWorld extends Spotlet
{
/** Stores a reference to the "Exit" button. */
private static Button exitButton;
/**
* Main entry point for this program.
*/
public static void main(String[] args)
{
(new HelloWorld()).register(NO_EVENT_OPTIONS);
}
/**
* Constructor: draws the screen.
*/
public HelloWorld()
{
// Create (initially invisible) the "Exit" button
exitButton = new Button("Exit",70,145);
// Get a reference to the graphics object;
// i.e. the drawable screen
Graphics g = Graphics.getGraphics();
g.clearScreen();
// Draw the text, "Hello World!" somewhere near the center
g.drawString("Hello World!", 55, 45, g.PLAIN);
// Draw the "Exit" button
exitButton.paint();
}
/**
* Handle a pen down event.
*/
public void penDown(int x, int y)
{
// If the "Exit" button was pressed, end this application
if (exitButton.pressed(x,y))
System.exit(0);
}
}