Java me 如何在LWUIT中切换表单
我想用LWUIT制作一个基本的移动应用程序,但是我在使用表单时遇到了困难,我不知道如何关闭表单,转到打开表单的表单 所以基本上在表单之间切换有困难,所以我需要一些关于这方面的帮助,还有比使用表单在屏幕上显示组件更好的替代方案吗 任何帮助都将不胜感激Java me 如何在LWUIT中切换表单,java-me,lwuit,Java Me,Lwuit,我想用LWUIT制作一个基本的移动应用程序,但是我在使用表单时遇到了困难,我不知道如何关闭表单,转到打开表单的表单 所以基本上在表单之间切换有困难,所以我需要一些关于这方面的帮助,还有比使用表单在屏幕上显示组件更好的替代方案吗 任何帮助都将不胜感激 Form a = new Form (); FlowLayout exampleLayout = new FlowLayout(); final Button button = new Button("1"); bu
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()方法。我想,我们不必关闭表单。 我们一次只需展示一张表格。 例如:
当你有一个表单a中的按钮触发
b.show()代码>您可以将表单更改为b表单。我想,我们不必关闭表单。
我们一次只需展示一张表格。
例如:
当你有一个表单a中的按钮触发b.show()代码>您可以将表单更改为b表单。首先,您需要将所有组件添加到表单中
对于运行某些窗体,最好的方法是使用线程。在LWUIT中,您有内置线程。您可以这样使用它们:
Display.getInstance().callSerially(new Runnable() {
public void run() {
.....
}
});
当然,您必须调用show()
函数来显示表单,首先您需要将所有组件添加到表单中
对于运行某些窗体,最好的方法是使用线程。在LWUIT中,您有内置线程。您可以这样使用它们:
Display.getInstance().callSerially(new Runnable() {
public void run() {
.....
}
});
当然,您必须调用show()
函数来显示表单LWUIT中没有表单的dispose方法。您只需调用另一个表单的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);
}
LWUIT中没有窗体的处置方法。您只需调用另一个表单的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);
}