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 tutorialPrevious
Next Section
9. Development using KJava event handling

Defining methods and event handlers page 6 of 6

Again, the main() method defines the main entry point for our application.

      public static void main(String[] args)

The default constructor, Scribble, initializes the member variables, clears the screen, and draws the initial frame.

      public Scribble()

The paint() method is responsible for updating or redrawing the display. It makes use of the class variable g -- a Graphics object similar to the one used in the Java 2 AWT.

      private void paint()

The penDown() method implements the event handler to handle the event of putting the stylus, or pen, on the screen. It passes in the X and Y coordinates. In our Scribble application, this method tests to see if either the Clear or Exit button was pressed and if so, handles those events.

      public void penDown(int x, int y)

The keyDown() method handles entering a graffiti letter on the graffiti writing area on your Palm device. The integer value, keyCode, passed into this method is the value of the character key entered. In the Scribble application we store the key pressed in the lastKey member variable then invoke the paint() method to update the screen.

      public void keyDown(int keyCode)

The penMove() method handles the event of dragging the stylus across the screen. In the Scribble application, it is responsible for drawing with the stylus.

      public void penMove(int x, int y)

The last method used, clearDrawingArea(), is the method invoked by the penDown event handler when the user taps the Clear button. It is a private method because it is intended only to be used internally within the Scribble class.

      private void clearDrawingArea()

Next Section
Main menuSection menuGive feedback on this tutorialPrevious