Skip to main content
IBM HomeProductsConsultingIndustriesNewsAbout 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 menuSection menuGive feedback on this tutorialPreviousNext
9. Development using KJava event handling

Handling keyboard input, beam send/receive, and unknown events page 3 of 6

In the J2SE AWT the java.awt.event.KeyListener interface includes keyPressed, keyReleased, and keyTyped methods for handling different keyboard events. Contrast this with KJava where only one such method exists, keyDown().

The keyDown event is invoked if the user writes a character on the graffiti area, taps the calculator or menu icon, or presses any of the "hard keys" (by default, these are the Date Book, Address, page up, page down, To Do List, or Memo Pad keys). The keyCode parameter identifies the code of the key the user enters. If one of the hard keys is pressed, the keyDown event will match one of the corresponding constants defined in this class.

public void keyDown( int keyCode )

The beamReceive() method is used for receiving packets of data from other Palm devices via infrared. The data is received in a byte array, which is allocated by the virtual machine automatically.

public static boolean beamReceive( byte[] data )

The beamSend() method is not an event handler, but is obviously related to the beamReceive() method so we'll include it here. It is used for beaming data packets to another Palm device via infrared. You can call this method explicitly to beam data to another device, however, the other device must have registered a beamReceive handler in its current spotlet to receive data.

public static boolean beamSend( byte[] data )

The unknownEvent is a general catch-all event handling routine.

public void unknownEvent( int event, in )

Main menuSection menuGive feedback on this tutorialPreviousNext