Re: Looping object creation
Quote:
are there even better ways of going about this?
Can you post the code? It be Easier to follow than the text given above
Re: Looping object creation
Ill get on it asap but Im going away to a friend today to get a few beers and my code is on my other comp. I'll do it tomorrow when I get home.
Re: Looping object creation
Like so:
Code :
//Create labels for all 81 elements in panel, store in Hashtable.
for (int i = 0; i < 81; i++){
labKey = "label" + i;
tempLabel = new JLabel("", 0);
tempLabel.addMouseListener(this);
labels.put(labKey, tempLabel);
}
//Add all labels to panel.
for(int i = 0; i < 81; i++){
panel.add((JLabel)labels.get("label" + i));
}
Re: Looping object creation
Why not do it in one loop?
Code :
//Create labels for all 81 elements in panel, store in Hashtable.
for (int i = 0; i < 81; i++){
labKey = "label" + i;
tempLabel = new JLabel("", 0);
tempLabel.addMouseListener(this);
labels.put(labKey, tempLabel);
panel.add(tempLabel);
}
Re: Looping object creation
Wanted to try out both the put and the get methods of hashtables. Haven't used em all that much before and practice makes perfect so I figured whattheheck :). More efficient to add them directly in the first for-loop tho, thx for the tip.