2012-01-01 214 views
0

我有幾個對象,其中包含變量以供標準使用。在GWT我想要做以下事情:GWT從對象動態獲取變量

public class myObject { 
    protected TextBox textbox1 = new TextBox(); 
    protected TextBox textbox2 = new TextBox(); 
    protected TextBox textbox3 = new TextBox(); 
    protected TextBox textbox4 = new TextBox(); 

    // pass name of field: textbox1, textbox2... etc. 
    public TextBox getMyTextbox(String fieldname) { 
    return this.... [fieldname]; 
    } 

} 

該部分返回此...是我真的沒有得到。任何幫助將受到歡迎。

+1

,你會做什麼,你真的不明白? :) 爲什麼要這麼做? :)這是什麼.... [fieldname]? – milan 2012-01-01 10:42:07

+0

浪漫的問題? – 2012-01-01 19:24:49

+0

@milan:功能我做getMyTextbox,但在我的腦海裏,我不知道該怎麼做,所以我不明白它;-)。 – MightyMouseTheSecond 2012-01-03 12:58:24

回答

0

你發現什麼困惑在這裏:

public TextBox getMyTextbox(String fieldname) { 
    if ("textbox1".equals(fieldname) { 
     return textbox1; 
    } else if ("textbox2".equals(fieldname) { 
     return textbox2; 
    } else if ("textbox3".equals(fieldname) { 
     return textbox3; 
    } else if ("textbox4".equals(fieldname) { 
     return textbox4; 
    } 
}