In Java, how to get attribute given the string with its name?

前端 未结 5 1077
粉色の甜心
粉色の甜心 2020-12-25 13:51

I\'m sorry for asking this sort of questions, but I really couldn\'t find the answer in Google. So say I have a class with private String myColor and I have a s

5条回答
  •  情深已故
    2020-12-25 14:31

    Based on the edit, my suggestion is to use a Map to contain a map of preference name to appropriate text field or other text component. Just build the map when you build the user interface.

    Map guiFields = new HashMap();
    

    Then you can have the code do

    guiFields.get(inputName).setText(value);
    

提交回复
热议问题