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.
|