TextEdit/TextBox onKey events in J2me

49 Views Asked by At

I'm developing (or trying to) a J2ME application. I need to be able to handle onKeyEvents (keyDown/keyPressed/keyUp...) in TextEdit/TextBoxes, but I've learned that such thing is not possible in J2me, at least not in a simple way as in Java/Android development (myEdit.setOnKeyListener() for example). I've read something about using Canvas, but I'm not sure how can I use that to make it work for me.

Answer to this question ( Image in button - j2me ) involves using the CustomItem class and make an item look/act like a Button. Is there anyway to use the same approach?

1

There are 1 best solutions below

0
mr_lou On

The TextBox and TextField objects are high-level GUI stuff, available when doing javax.microedition.lcdui.Form stuff.

In order to use keyPressed() and keyReleased() you must use javax.microedition.lcdui.Canvas (low-level GUI stuff).

But what you're probably really after, is LWUIT (https://lwuit.java.net). It is a framework built on javax.microedition.lcdui.Canvas which gives you a Form-like API with all the things javax.microedition.lcdui.Form is missing.