I'm looking for a way to quickly select Java and set a text for multiple labels in my Java application.
I have a Java app that checks \ stops \ checks windows status I have a method, which has passed an array of these service names and each of these services Has an identical label with its position in it. For example, DummyService1 is contained in the array and there is a label called txt_DummyService1 My method (short version) does the following
public static zero checker (string array []) {/ / Dummy eseris 1 check status "txt _" + dmissice Text = "start"; } I know that this is not the way that you do this, but can someone help me do the best way to do this?
In this way to generate a "variable" name from a string There is no way Yes, you can use reflection, but already question about the quality of the designs agreed. Instead, mark each label by name in the map . Private map & lt; String, JLab & gt; LabelLookup = new hashmap & lt; & Gt; (25); // instance variable. In the constructor (or wherever you make your UI), add each label to map . / * Other UI code * / label lookup.Put ("Dmmeceiver 1", TCTDMissService1); Now, when you need to make changes, see the label of its name,
// You have a better way to do this It's stabilizing ... Public Zero Checker (string services []) {for (string service: services) {JLabel label = labelLookup.get (service); If (label! = Null) {label.setText ("Start"); }}} For example ...
No comments:
Post a Comment