Skip to main content

IBM  
Shop Support Downloads
IBM Home Products Consulting Industries News About IBM
IBM : developerWorks : Java Technology : Education - online courses
J2ME: Step by step
Download tutorial zip fileView letter-sized PDF fileView A4-sized PDF fileE-mail this tutorial to a friend
Main menu Section menu Give feedback on this tutorial Next
9. Development using KJava event handling

Introduction page 1 of 6



In this section we will explore KJava event handling, and demonstrate how it works with our simple drawing application, Scribble.

The KJava event handling model is fairly rudimentary compared to J2SE's action-listener event handling model. All events of interest are accessible by subclassing the Spotlet class, which your KJava application will do anyway. Only the spotlet that currently has the focus is notified of the event. To give a spotlet the focus, use the register() method. To stop being notified of events, use the unregister() method.

Note: If you register a spotlet with WANT_SYSTEM_KEYS, the device will not terminate the application automatically by trapping the button press and queueing an application that stops it. Instead, the application will be notified of the button press event, and will then be responsible for handling that event appropriately. The application will continue to run indefinitely unless you provide a way to terminate it by calling System.exit when a button is pressed. Otherwise, the only way to stop the application is to reset the device.

KJava supports three basic types of events: pen movements, keyboard input, and beam send/receive. In addition, there is a general catch-all method, unknownEvent(). We will discuss these different types of events.


Main menu Section menu Give feedback on this tutorial Next
Privacy Legal Contact