0

I am developing one project using LWUIT, Midlet mobile Application. when I press number keys a dialog box will open. when i press the keys #,0,* Dialog should be close.
I am using Dialog.dispose() method to close dialog. But it is not working. Below is my Code. Can anyone tell me what is the problem in my code?

public class javaForm extends Component implements ActionListener
{

Dialog d=new Dialog();


public void keyPressed(int key){

     System.out.println("Key pressed :"+key);

            switch(key)
            {


                case 48:
                    d.show(130,20,30,30,true);
                    break;
                case 49:
            d.show(130,20,30,30,true);
                    break;
                case 50:
            d.show(130,20,30,30,true);
                    break;
                case 51:
             d.show(130,20,30,30,true);
                    break;
                case 52:
             d.show(130,20,30,30,true);
                    break;
                case 53:
            d.show(130,20,30,30,true);
                    break;
                case 54:
            d.show(130,20,30,30,true);
                    break;
                case 55:
             d.show(130,20,30,30,true);
                    break;
                case 57:
                    d.show(130,20,30,30,true);
                    break;
                case 56:
                     d.show(130,20,30,30,true);
                      break;
                case 42:
            d.dispose();
                        break;
                case 35:
                        d.dispose();
                        break;
                default:
                       d.dispose();
                       break;
            }

}

public void actionPerformed(ActionEvent ae) 

{

 throw new UnsupportedOperationException("Not supported yet.");

}

}

Actually javaForm is a java Program developed using LWUIT and am calling this javaForm inside of MIDLET which is javaForm1. I Included all the Necessary packages.

gnat
  • 6,213
  • 108
  • 53
  • 73
Shankar
  • 31
  • 8
  • 2
    you should accept your other questions before asking new – frayab Jan 11 '12 at 08:39
  • Have you check the key code for that keys? [Already I told you](http://stackoverflow.com/questions/8799366/how-to-resize-dialog-box-in-lwuit) to use println inside of the case and see what happened. – bharath Jan 11 '12 at 09:16
  • yes @ Bharath. i tried , but not Works.i pressed key 2 and it displayed 50. again i pressed 2 it doesn't print anything – Shankar Jan 11 '12 at 09:19
  • Totally agree with @frayab.You must accept other questions. It is important if you want to get answers. – Mun0n Jan 11 '12 at 16:31

1 Answers1

2

Why don´t you use Form.addGamekeyListener()?

Put the gameKeyListener in yout Form (extends ActionListener in the Form)and later in the actionPerformed(ActionEvent ae) capture the key with ae.getKeyEvent and close the Dialog.

Map the GameKeys with Canvas. For example: Canvas.FIRE.

Mun0n
  • 4,438
  • 4
  • 28
  • 46
  • @ jmunoz.. what are the keys comes under GameKeyListener.I want Use all of the mobile Keys to show Dialog,to Dispose Dialog.. – Shankar Jan 12 '12 at 06:25
  • 1
    Use addKeyListener instead of game key listener just as jmunoz explained. You can also subclass dialog and override the keyReleased callback. – Shai Almog Jan 12 '12 at 06:39
  • 1
    For what? Form.addKeyListener() is like game key listener. Overriding a method is just deriving LWUIT's Form and declaring public void keyReleased(int keyCode) {...} – Shai Almog Jan 15 '12 at 12:49