2011-07-27 19 views
1
public class StateMachine extends StateMachineBase { 

public Container con1; 

protected void beforeMainForm(Form f) { 
      con1 = findMenucon(f);<Br> 
      super.beforeMainForm(f);<br> 
    } 
} 

//class mainmidlet() 
public void run() { 

    try { 
     //new StateMachine("/App.res"); 
     new mainform("/App.res"); 
    } catch (Exception ex) { 
     ex.printStackTrace(); 
    } 
} 


class mainform implements ActionListener{ 

Vector bname; 
Button[] b; 
String mainmenu=null; 
Form frm; 
mainform(String string) { 

try { 
Resources res = Resources.open(string); 
UIManager.getInstance().setThemeProps(res.getTheme(res.getThemeResourceNames()[0]));   

UIBuilder builder = new UIBuilder(); 
frm = (Form)builder.createContainer(res, "MainForm"); 
StateMachine sm=new StateMachine("/App.res"); 
System.out.println("------->>>"); 
bname=new Vector(); 
this.readmenu(); 
b = new Button[bname.size()]; 
System.out.println(b.length+bname.toString()); 
     for (int i = 0; i<b.length; i++) { 
      b[i] = new Button(bname.elementAt(i).toString()); 
      b[i].setAlignment(Label.CENTER); 
      b[i].getStyle().setMargin(2,5,5,5); 
      b[i].getStyle().setPadding(5,5,5,5); 
      System.out.println(b[i].toString()); 
      b[i].addActionListener(this); 
      sm.con1.addComponent(b[i]); 
      //System.out.println("\n " + b[i]); 
    } 
frm.addComponent(sm.con1); 
frm.show(); 
} 
catch(IOException err) { 
err.printStackTrace(); 
} 

public void actionPerformed(ActionEvent ae) { 
    throw new UnsupportedOperationException("Not supported yet."); 
} 

我正在使用上述代碼創建動態Button使用json。我可以得到在控制檯的價值,但不能獲得ButtonForm動態按鈕創建到使用lwuit 1.4的形式

+0

上做了重新驗證()如果你的'JSON'值加到' bname'? – bharath

+0

readmenu(){bname.addElement(jarray.get(i));};我可以得到控制檯中的按鈕值....但按鈕不是以 – raja

回答

1

這顯然是不正確的使用狀態機(這不是1.4 BTW的一部分),因爲基類將創建並顯示窗體上它自己並設定自己的主題(壓倒你之前做的任何事情)。

您還忽略了包括con1的創建/定義,並且包含對將不在設備上運行的UnsupportedOperationException的調用。

所有的LWUIT代碼都應該在狀態機中,請按照包括T區演示在內的演示,我們會​​立即替換標題以創建動畫。所有這些代碼完全在狀態機中,我們覆蓋特定的表單初始化方法並從那裏修改表單。

如果您想手動寫入所有內容,請不要使用狀態機,直接使用UIBuilder即可。

+0

的形式創建的,謝謝Shai Almog ..... – raja

0

我想你應該構建您的按鈕後,你仍然可以將其添加到窗體即使展會結束後,該表

frm.revalidate(); 
+0

謝謝......彼得........ – raja