O hai
So basically, I was working on my soduko-program when I got one of them "eureka-moments" and I thought I should share. I love the cafe so I'm posting it here but it's prolly missplaced so put it where you want it.
I'm basically using 81 labels which are clickable to make the 9x9 playing-field. Creating 81 labels is hell if you do it manually, not to speak of the fact that it looks like crap in your code when you have 81 listeners, adds and creations of labels. So basically I wanted a way of creating 81 labels in a simple for loop. The problem, obviously, is that if you just do JLabel label = new JLabel(); 81 times your 80 first ones get avaiable for garbage collection since they have no pointers anymore, and you cant do JLabel STRINGX = new JLabel() either (which sucks, gogo make this possible ploz Sun).
So I'm basically making a hashmap, giving the value of the first button's key the value (label + i ) and then using i++ in the for-loop, so button 1 becomes button1, button 2 becomes button2 etc.
Right now you're thinking "So why the hell are you here bragging about it?" and theres actually a good answer:
I've been scouring forums all over for a sollution for this issue and I haven't found jack on it, and from looking around on this forum I can tell many of you are in the same situation I'm in, having to create 50+ objects that just differ extremely little in state and name. Even if you want to create say 2 different kinds of buttons, you can store object names/states in string arrays and use the array elements to set those specific values like:
name[x] = "name x"; and value[x] = "value x"; ...you prolly get the idea.
Hope this helps someone as much as it helps me, and is this actually used by anyone except me or are there even better ways of going about this?
Love
// Charlie