How to handle keystrokes in a J2ME GUI application
I have programmed bluetooth Television-Remote control for mobile phones in J2ME using javax.microedition.lcdui.*
(Gauge, List, ChoiseGroup) GUI-Elements.
I want the cell phone to have real-time interaction with my TV, I would like to find a way to immediately send custom inputs made with GUI-Elements (like change channel or change volume) to the TV.
Since I require real-time interaction with my TV, I would like to find a way to immediately send custom inputs made with GUI-Elements (like change channel or change volume) to the TV.
Using javax.microedition.lcdui.Command
/ CommandListner
and commandAction
won't work as they have to recognize the commands selected with the side buttons. I would like to have something that can recognize any key pressed.
I found I Javax.microedition.lcdui.Canvas.keyPressed
can handle any key pressed on a mobile, but I don't know how to get Canvas to work with MIDP GUI elements like Gauge. They cannot be added as Commands.
Should I figure out a way to create an interface for these GUI elements to make them work with Canvas?
I found half the solution myself, in case anyone is interested: "Javax.microedition.lcdui.ItemStateListener". This function can handle states (or state changes) of GUI elements in real time. Its not keyPress, but this will work for my application too.
According to this FAQ, you cannot do what you ask for. This is for MIDP 1.0, but I believe this also applies to MIDP 2.0. If you only need a pressure gauge, you can easily draw one yourself.
From what I've seen, this can only be done with Canvas .
I highly recommend that you either draw your gauge-like object to a Canvas object or follow the guidelines outlined on Dec 19 at 15:00 "zhengtonic". I don't know any other approach to this problem, I was there but used the first options provided by me