2013-06-18 60 views
0

我想使用LWUIT制作一个基本的移动应用程序,但在使用窗体时遇到困难,我不知道如何关闭表单以转换为打开窗体。如何在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找回形成没有Close方法或Dispose()方法礼物表格

回答

1

我认为,我们没有关闭的形式。 我们一次只能显示一种形式。 例如:

a.show(); 

当你有形式的按钮,其触发b.show();可以更改形式为a〜b的形式。

+0

是啊,现在知道了感谢 – user2497398

0

首先,您需要添加所有组件以形成。

对于运行某些形式最好的方法是使用线程。在LWUIT中你有内置的线程。你可以使用他们喜欢的是:

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

当然,你必须调用show()函数来显示形式

+1

如果你已经在美国东部时间你不需要做 –

2

有在LWUIT形式没有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); 
} 
+0

感谢一吨....这帮助了很多 – user2497398

+0

很好,@ user2497398,随时接受回答然后;) – igordsm