Simple Spotlet
       

Simple Spotlet

This example is even more basic than the HelloWorld example shown elsewhere on this page. In this example, we bring up a Simple Spotlet, with no event handling, and no way of closing the spotlet other than using the "Application" key on the Palm Pilot to go back to home.

// works on Preview and EAv0.1 versions
import com.sun.kjava.*;

/** Most basic of all examples, we extend a Spotlet, and merely draw
 *  some text on the screen.  Note that there is no event handling of
 *  any kind, including exiting the Spotlet.
 */ 
public class SimpleSpotlet extends Spotlet {
    
    // handle on the singleton Graphics object
    static Graphics g = Graphics.getGraphics();
    
    /**
     * The main method simply creates a Scribble spotlet and
     * registers its event handlers.
     */
    public static void main(String[] args) {
        SimpleSpotlet testSpotlet = new SimpleSpotlet();
	testSpotlet.register(NO_EVENT_OPTIONS);
    }
    
    /**
     * Default constructor creates the GUI components and draws them.
     */
    public SimpleSpotlet() {
	// paint the text
	paint();
    }
    
    /**
     * Draw the screen
     */
    private void paint() {
	g.clearScreen();
	g.drawString("Simple Spotlet",60, 80);
    }
}

Items of Note in this program.
  1. This class extends Spotlet, which provides callbacks for event handling. Applications extend Spotlet and override the relevant event handling methods. An application may use more than one Spotlet object, but at most one Spotlet can have the focus at any one time. That is, events will only trigger the callbacks of one Spotlet at any given time, the Spotlet with the current focus.

    To become the focus, a Spotlet invokes the register method which also removes the focus from the previously registered Spotlet (if any).

    So in the above example, we have:

    public class SimpleSpotlet extends Spotlet {
    ...    
        public static void main(String[] args) {
            SimpleSpotlet testSpotlet = new SimpleSpotlet();
    	testSpotlet.register(NO_EVENT_OPTIONS);
        }
    ...
    
  2. The register(int) method above registers the event handlers of this object. This registration is the method which gives the Spotlet the focus for event handling. A side effect this is that all previously registered handlers (if any) are unregistered and the Spotlet to which they belong loses the focus.

    The parameters to register(int) are either NO_EVENT_OPTIONS or WANT_SYSTEM_KEYS

  3. Lastly, the string Hello World is painted to the screen by overriding the paint method in the Spotlet.

        public SimpleSpotlet() {
    	paint();
        }
        
        private void paint() {
    	g.clearScreen();
    	g.drawString("Simple Spotlet",60, 80);
        }
    

    Note three items in this block of code,