Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私は JFrame を使用しており、変数名を含む文字列を持っています。その変数の値を取得したい。
String temp = "dim"; double temp_value = Double.parseDouble(temp.getText());
ここで、dimswing ライブラリを使用する JFrame の変数の名前です。通常、変数の値を取得するには、コードの 2 行目を使用します。この場合、どうすればよいでしょうか??
dim
リフレクション API を使用する必要があります。
JFrame frame; // Instance of your JFrame ... ... String temp = "dim"; Object value = frame.getClass().getField(temp).get(frame);