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.
Why donĀ“t you use
Form.addGamekeyListener()
?Put the
gameKeyListener
in youtForm
(extendsActionListener
in theForm
)and later in theactionPerformed(ActionEvent ae)
capture the key withae.getKeyEvent
and close theDialog
.Map the GameKeys with
Canvas
. For example:Canvas.FIRE
.