2012-01-01 16 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

+0

ロマンチックな質問ですか? –

+0

@milan:functional私はgetMyTextboxを行いますが、私の心の中で私はそれをどうやって行うのか分かりません;-)。 – MightyMouseTheSecond

答えて

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; 
    } 
} 
関連する問題