I have a problem with loops. I need to access 10 labels that have names like label1, label2, label3 .... etc. I need to know if I can access these shortcuts after going through a loop in java?
How about using List or array
List
array
List<JLabel> labels = new ArrayList<JLabel>(); labels.get(index);
Change these labels as an array and access it with an index.
For instance:
JLabel[] labels = new JLabel[10]; for (int i = 0; i < labels.length; ++i) { labels[i] = new JLabel("Label " + i); } for (int i = 0; i < labels.length; ++i) { // access each label. }
Put your tags in a LinkList or array Then you can access these arrays or linkList in a loop
If you cannot change the names of the shortcuts / put them in an array, you can create an array of shortcuts to tags and fill it at the beginning of your program with a list of your tags.
"Shortcut access" is fuzzy. Do you mean different instances of java.awt.label? If so, you can simply iterate over them, when they are in the list, for each operator.
If you are talking about Java shortcuts, you can use the switch statement instead. If you are talking about objects like JLabel, use an array or ArrayList.