在j2me中显示alert然后跳转到另一个表单
我正在开发 J2ME 应用程序。我想在表单中显示警报并显示另一个班级的另一个表单。我尝试过以下方法来显示警报。
public void showMsg()
{
Alert success = new Alert("Data Not found.");
//success.setImage(img2);
success.addCommand(new Command("Ok", Command.OK, 0));
success.addCommand(new Command("Cancel", Command.CANCEL, 0));
success.setCommandListener(this);
success.setTimeout(Alert.FOREVER);
Display.getDisplay(parent).setCurrent(success, chapterForm);
}
显示警报后,我跳转到另一个表单:
Display.getDisplay(parent).setCurrent(welcomeForm);
当我运行此表单时,它不显示警报,而是跳转到 welComeForm。那么,我怎样才能显示警报,然后跳转到另一种形式。
I am working on J2ME application. I want to show alert in Form and display another Form from another class. I have tried the following method to show alert.
public void showMsg()
{
Alert success = new Alert("Data Not found.");
//success.setImage(img2);
success.addCommand(new Command("Ok", Command.OK, 0));
success.addCommand(new Command("Cancel", Command.CANCEL, 0));
success.setCommandListener(this);
success.setTimeout(Alert.FOREVER);
Display.getDisplay(parent).setCurrent(success, chapterForm);
}
After showing the alert I am jumping to another form as:
Display.getDisplay(parent).setCurrent(welcomeForm);
When I run this it don't show the alert but jump to the welComeForm. So, how can I show alert and then jump to another form.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
警报不会自动前进到
chapterForm
,因为您已将警报上的默认侦听器替换为this
。使用 CommandListener 接口中的 commandAction() 事件从警报中获取“确定”或“取消”。然后你可以使用Display.setCurrent(Displayable d)
来显示你想要显示的Form。The Alert won't advance automatically to
chapterForm
because you have replaced the default listener on the Alert withthis
. Use the commandAction() event in the CommandListener interface to get the OK or Cancel from the Alert. Then you can useDisplay.setCurrent(Displayable d)
to show the Form you want to display.Display.getDisplay(parent).setCurrent(welcomeForm)
很可能是它不显示警报而是跳转到 welcomeForm 的原因。准确地说,它(设备)可能会暂时显示警报,但是一旦您调用setCurrent(welcomeForm)
,它就会立即被welcomeForm 覆盖。如果您希望通过警报命令显示
welcomeForm
,只需从现在的位置删除代码
setCurrent(welcomeForm)
将擦除的代码插入
this.commandAction
方法(this
是您在代码摘录中使用的命令侦听器)Display.getDisplay(parent).setCurrent(welcomeForm)
is most likely the reason why it don't show the alert but jump to the welComeForm. To be precise it (device) may show alert for a moment, but as soon as you invoke thatsetCurrent(welcomeForm)
, it gets momentarily overwritten by welcomeForm.If you want
welcomeForm
to be dissplayed by command from alert, justwipe out the code
setCurrent(welcomeForm)
from where it is nowinsert that wiped-out code into
this.commandAction
method (this
is command listener you use in your code exerpt)一个巧妙的解决方案是在将当前显示设置为警报后启动一个新线程,在这个新线程中您可以执行 Thread.sleep(2000);为了等待,然后显示新表单。
A nifty solution is to start a new thread after setting the current display to the Alert, and in this new thread you can do a Thread.sleep(2000); in order to wait, and after that you display the new form.