【问题标题】:how to switch between forms in LWUIT如何在 LWUIT 中的表单之间切换
【发布时间】:2013-06-18 13:43:18
【问题描述】:

我想使用 LWUIT 制作一个基本的移动应用程序,但在使用表单时遇到困难,我不知道如何关闭表单以转到我打开它的表单。

所以基本上无法在表单之间切换,所以我需要一些帮助,还有比使用表单在屏幕上显示组件更好的替代方法

任何帮助将不胜感激

   Form a = new Form (); 
   FlowLayout exampleLayout = new FlowLayout(); 
   final Button button  = new Button("1");

    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
             Form b = new Form ();
            //how to get back form this form b to form a 
        }
    });

我不知道如何从表单 b 回到表单 a 表单没有 close 方法或 dispose() 方法

【问题讨论】:

    标签: java-me lwuit


    【解决方案1】:

    LWUIT 中没有针对 Forms 的 dispose 方法。您只需调用另一个 Form 的 show() 方法来替换旧的。由于 LWUIT 是为使用少量内存而构建的,因此它会在将旧表单替换为新表单之前处理其对旧表单的引用。如果“新”表单只是使用“后退”按钮访问的旧表单,则可以使用 showBack()。此方法反转表单转换,使其看起来“重新进入视图”。这是一个例子。

    public void showA(boolean back) {
        Form a = new Form (); 
        a.setTitle("AAAA");
        FlowLayout exampleLayout = new FlowLayout(); 
        final Button button  = new Button("1");
    
         button.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent evt) {
                  showB(false);
             }
         });
         a.addComponent(button);
         a.setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 1000));
         if (back) {
             a.showBack();
         } else {
            a.show();
         }
    }
    
    public void showB(boolean back) {
        Form b = new Form ();
        b.setTitle("BBBBB");
        FlowLayout exampleLayout = new FlowLayout(); 
        final Button button  = new Button("1");
        Command c = new Command("Back") {
            public void actionPerformed(ActionEvent evt) {
                showA(true);
            }
        };
        b.setBackCommand(c);
        b.addCommand(c);
    
    
        button.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent evt) {
                  showA(false);
             }
         });
         b.setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 1000));
         b.addComponent(button);
         if (back) 
             b.showBack();
         else
             b.show();
    }
    
    public void startApp() {
        Display.init(this);
        showA(false);
    }
    

    【讨论】:

      【解决方案2】:

      我认为,我们不必关闭表单。 我们一次只需要展示一种形式。 示例:

      a.show();
      

      当您在表单 a 中有一个触发 b.show(); 的按钮时,您可以将表单更改为 b 表单。

      【讨论】:

        【解决方案3】:

        首先,您需要将所有组件添加到表单中。

        对于运行某些表单,最好的方法是使用线程。在 LWUIT 中,您有内置线程。你可以这样使用它们:

        Display.getInstance().callSerially(new Runnable() {
                    public void run() {
                        .....
                    }
        });
        

        当然你必须调用show()函数来显示表单

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-11-25
          • 1970-01-01
          • 1970-01-01
          • 2023-03-23
          • 2013-06-06
          • 1970-01-01
          • 1970-01-01
          • 2014-01-29
          相关资源
          最近更新 更多