2011-07-04 137 views
1

如何調用另一個表單?當我使用form.show()方法時,不顯示另一個表單的組件。
例...在J2ME中使用LWUIT庫。如何調用另一個表單?

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() 
    { 
     .... 
     . .... 
    } 
} 

回答

2

首先,你必須在你的類FirstForm創建表格。 像Form frm=new Form("First Form"); 然後添加命令你cmd_Login在形式上像frm.addCommand(cmd_Login); 然後設置命令監聽形成frm.setCommandListener(this); &需要在FirstForm implements CommandListener沒有的ActionListener。 然後在public void commandAction(Command c, Displayable d) {現在你必須編寫代碼去第二個表單。 &有一件事我注意到你的登錄類,你總是擴展類形式&也在登錄類中創建表單對象...如果您使用擴展類表單然後不創建表單對象。 感謝

+0

嘿sajid感謝重播yaar。在登錄表單中必須定義組件的所有定義在登錄構造函數中。如果不是什麼是solution.plz舉一些例子。非常感謝你 –

+0

它幾乎是必要的........ –

+0

你沒有另一種選擇 –

1

只需使用

new Login().show(); 
+0

嘿Nirmal感謝重播。 –

+0

在登錄表單中,必須定義登錄構造函數中組件的所有定義。如果不是什麼是solution.plz舉一些例子。十分感謝 –

0

我發現打電話從內其他形式的最佳方式,實施監聽後就是用這樣的:showForm("name of Form", null);

另一種方式來調用另一種形式,但是從一個組件的動作是這樣的:showContainer("name of Form",c, null);

0

該行在Display.init(this)之前被調用;因此你會得到一個例外,沒有任何工作。

Form frm_first = new Form("First"); 

Display.init(this)代碼後移動初始化代碼。

相關問題