Search code examples
user-interfacecanvasjava-memidpmidp-2.0

How to handle the key presses in a J2ME GUI application


I programmed a bluetooth Television-Remote control for cellphones in J2ME using javax.microedition.lcdui.* (Gauge, List, ChoiseGroup) GUI-Elements.

I want the cellphone to have real-time interaction with my Television, I would like to find way to send user inputs performed with the GUI-Elements immediately (like changing the channel, or changing the volume) to the Television.

Since I want real-time interaction with my Television, I would like to find way to send user inputs performed with the GUI-Elements immediately (e.g. changing the channel, or changing the volume) to the TV.

Using javax.microedition.lcdui.Command / CommandListner and commandAction won't work since these need only recognize the commands selected with the side buttons. I would like to have something that can recognize any key pressed.

I discovered that Javax.microedition.lcdui.Canvas.keyPressed can handle any key pressed on the cellphone, but I don't know how to make Canvas work with MIDP GUI elements like Gauge. They can't be added like Commands.

Do I have to figure out way to build a interface for these GUI elements to make them work with Canvas?


Solution

  • I just found a half solution myself, if anyone is interested: "javax.microedition.lcdui.ItemStateListener". This function can handle the states (or state changes) of the GUI items in realtime. Its not keyPress, but this will work as well for my application.