
Originally Posted by
ektasrv
You can do the required by overwriting the keypressed(int key) method of the current LWUIT displayable on the screen and do the needful w/o passing it to the supper in case you want to capture a key.
Thanks for the reply...
What's the problem with this code :
PHP Code:
package hello;
import com.sun.lwuit.Component;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.*;
/**
* @author java
*/
public class KeyPadMidlet extends MIDlet implements CommandListener {
Display display = null;
Form form = null;
Label lbl = null;
public void startApp() {
display = Display.getInstance();
Display.init(this);
form = new Form("KEY FORM");
lbl = new Label();
form.show();
form.addComponent(lbl);
form.addComponent(null, new keyListener(true));
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void commandAction(Command cmnd, Displayable dsplbl) {
}
class keyListener extends Component {
boolean fl = false;
public keyListener(boolean flag) {
this.fl = flag;
}
public void keyPressed(int keycode) {
if(fl==true){
super.keyPressed(keycode);
int k_code = Display.getInstance().getKeyCode(keycode);
switch (k_code) {
case Display.GAME_UP:
lbl.setText("" + k_code);
break;
case Display.GAME_DOWN:
lbl.setText("" + k_code);
break;
default:
break;
}
}}
}
}
It is not printing the keycode value to the label. And how will i get the keycode values for 1to 9 keys.
Please Reply.