Home > Nokia, Programming > Touch Event Programing on MIDP2.0

Touch Event Programing on MIDP2.0

April 20th, 2009 Leave a comment Go to comments

There is some difficulties running some of MIDP applications on Nokia 5800XM. Because 5800XM only has a few hardware keys. Native S60 5th applications utilize touch screen of 5800XM, but ordinal MIDP applications do not.

Standard UI components on 5800XM support touch screen event naturally. The problem is when MIDP applications uses 10keys for specific application behavior. We may utilize low level touch events instead of 10keys.

I just tested how we can use touch events of 5800XM on MIDP2.0 applications.

Canvas class of MIDP2.0 has call back API entries pointerPressed(int x, int y), pointerReleased(int x, int y) and pointerDragged(int x, int y). And also boolean hasPointerEvents() to check those event APIs on the device. Those API entries are designed for any kind of pointing devices. Touch screen is just one of them.

Those call back API entries are very easy to use…

public void pointerReleased(int x, int y)
{
    iPointX = x;
    iPointY = y;
    this.repaint();
}

This is very simple, but effective. I setup the code to write iPointX and iPointY values to the screen in paint routine. This works fine on S60 5th emulator.

Therefore, if we draw virtual keys or buttons on the screen and MIDP program can recognized them by touch event API like pointerReleased. We can use this mechanism to start specific application behavior instead of 10 keys.

Categories: Nokia, Programming Tags:
  1. No comments yet.
  1. No trackbacks yet.