【问题标题】:Display alert and then jump to another form in j2me显示警报然后跳转到 j2me 中的另一个表单
【发布时间】:2013-07-22 05:04:54
【问题描述】:

我正在开发 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。那么,我怎样才能显示警报然后跳转到另一个表单。

【问题讨论】:

    标签: java java-me midp lcdui


    【解决方案1】:

    警报不会自动前进到chapterForm,因为您已将警报上的默认侦听器替换为this。使用 CommandListener 接口中的 commandAction() 事件从 Alert 中获取 OK 或 Cancel。然后你就可以使用Display.setCurrent(Displayable d)来显示你想要显示的Form了。

    【讨论】:

      【解决方案2】:

      Display.getDisplay(parent).setCurrent(welcomeForm) 很可能是它不显示警报而是跳转到welComeForm 的原因。准确地说,它(设备)可能会暂时显示警报,但是一旦您调用该setCurrent(welcomeForm),它就会被welcomeForm 暂时覆盖。

      如果您希望通过警报命令显示welcomeForm,只需

      1. 从现在的位置清除代码setCurrent(welcomeForm)

      2. 将删除的代码插入this.commandAction 方法(this 是您在代码摘录中使用的命令侦听器)

      【讨论】:

        【解决方案3】:

        一个不错的解决方案是在将当前显示设置为警报后启动一个新线程,在这个新线程中您可以执行 Thread.sleep(2000);为了等待,然后显示新表单。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-12-23
          • 2018-07-20
          • 2016-09-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多