2012-01-01 213 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; 
    } 
}