Get KeyCode from Dialog in lwuit

111 Views Asked by At

I want to invoke the keyListener and get the keyCode while the dialog is being shown. I have tried extending Dialog and overrided the keyReleased() with no success. Below is my code, what went wrong?

public class MyDialog extends Dialog{

public void keyReleased(int keyCode) {
    super.keyReleased(keyCode); //To change body of generated methods, choose Tools | Templates.
    System.out.println("Keycode in Dialog: "+keyCode);
}

}

And in my form, I am using the custom Dialog like below:-

MyDialog dialog  = new MyDialog();
dialog.show("INFO", "TEST CONTENT", "OK", "CANCEL");
1

There are 1 best solutions below

0
On

You aren't using your dialog.

show(String, String, String, String) is a static method not an instance method so a new dialog instance is created and shown.

You need to use show() which is an instance method (or some other instance method like showDialog), but then you will have to actually add the components and "construct" your dialog.