Okay first off, I've created a set of swing buttons. There are a lot of them and with names which refer to their position on the screen e.g a1-a9, b1-b9
for (int i=1;i<9;i++)
{
String name;
name = "a" + Integer.toString(i);
name.addActionListener(this);
}
so obviously i want to add ActionListener to the buttons, but i have a problem. How do i get it to use the String within name as the button name, for example here it'd be a1-a9. Do i use a map or reflection?
Secondly is there a way of creating an array of buttons. Obviously an array can only take primary types, my ultimate goal is to create a tiled grid for creating a simple connect 4 game. Instead of just creating each button individually creating them as an array using a for loop to increment button names.
My first go at creating a java game!
Social Networking Bookmarks