在J2me应用程序中,我使用了yes,no命令的警报。如果用户单击yes命令将显示Form屏幕,如果单击no命令,将显示TextBox屏幕。但代码不起作用。对于两个命令,仅显示文本框屏幕。
这是我的代码:
public Login(){
yes=new Command("Yes",Command.OK,1);
no=new Command("No",Command.CANCEL,1);
alert=new Alert("","Save The Changes?",null,AlertType.CONFIRMATION);
alert.setTimeout(Alert.FOREVER);
alert.addCommand(yes);
alert.addCommand(no);
textbox.setCommandListener(this);
alert.setCommanListener(this);
}
public void commandAction(Command command, Displayable displayable) {
if(displayable==textbox)
{
if(command==exit)
{
switchDisplayable(null,alert);
}
}
else if(displayable==alert)
{
if(command==no)
{
switchDisplayable(alert,getForm());
}
else if(command==yes)
{
switchDisplayable(alert,getTextbox());
}
}
}
我的错在哪里?
答案 0 :(得分:-3)
您的主要错误是我认为您的MIDlet中没有使用适当的logging。除此之外,您发布的代码段中没有明显的错误。
错误很可能是由getForm()
方法代码中的错误引起的,但由于没有日志记录,您还必须检查其他可能性,例如命令侦听器或{{1}命令对象,或者no
对象在代码中的其他位置以某种方式被更改。
如下面的示例所示,您可以在模拟器中运行midlet并检查控制台消息,以确定是否已执行预期的代码:
alert