How can I Dispose Dialog box From LWUIT Component

本秂侑毒 提交于 2019-12-31 07:20:46

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8814257/how-can-i-dispose-dialog-box-from-lwuit-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!