如何调用另一个窗体?当我使用form.show()
方法时,不显示另一个窗体的组件。
例如。
FirstForm.java
public class FirstForm extends MIDlet implements ActionListener
{
Form frm_first = new Form("First");
public Command cmd_Login;
public void startApp()
{
Display.init(this);
cmd_Login = new Command("Login");
frm_first.addComponent(cmd_login);
......
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void actionPerformed(ActionEvent ae)
{
Command cmd = ae.getCommand();
String strcmdName = cmd.getCommandName();
if (strcmdName.equals("Login"))
{
//how to call Login Form
}
}
}
Login.java
public class Login extends Form implements ActionListener
{
Form frm_Login = new Form("Login");
Button btn_Login = new Button("Login");
public Login()
{
....
. ....
}
}
发布于 2011-07-04 10:29:46
首先,您必须在FirstForm类中创建表单。像Form frm=new Form("First Form");
一样,然后以像frm.addCommand(cmd_Login);
这样的形式添加命令,然后将命令cmd_Login设置为form frm.setCommandListener(this);
&在FirstForm中需要是implements CommandListener
,而不是ActionListener。然后,在public void commandAction(Command c, Displayable d) {
中,现在你必须编写代码才能进入第二种形式。我在你的Login类中注意到一件事,你总是在Login类中扩展类Form和创建Form对象...如果你使用的是扩展类Form,那么不要创建Form对象。谢谢
发布于 2011-07-04 10:30:54
只需使用
new Login().show();
发布于 2012-02-03 12:49:19
在实现侦听器之后,我发现从一个窗体内部调用另一个窗体的最好方法是使用以下代码:showForm("name of Form", null);
调用另一个窗体的另一种方法是从组件操作内部调用:showContainer("name of Form",c, null);
https://stackoverflow.com/questions/6569903
复制相似问题