Well, this is my first post on here... I've found your message boards very useful when searching for problems so I decided to register and ask for help on this one since it's a little more specific than what I could find...
I've had 3 semesters of programming in college and I'm learning gooie programming on my own..
Here's the code where I keep getting stuck (btw, this is part of a bigger program -- im actually making a minesweeper game, but this is what you need to know from the area I have my problem). I made it so you can just copy and paste it to test on your own:
public class test extends JFrame{
GameButton[][] grid = new GameButton[16][30];
public static void main(String[] args){
test m = new test();
m.foo();
}
private class GameButton extends JButton{
private GameButton(int num){
this.num = num;
}
private int num;
}
public void foo(){
for (int i = 0; i<grid.length; i++){
for (int j = 0; j<grid[0].length; i++){
grid[i][j] = new GameButton(i);
grid[i][j].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
//performClickAction((GameButton)ae.getSource());
}
});
//add(grid[i][j]);
}
}
}
}
the arrayindexoutofboundsexception comes up when adding action listeners to grid[j] (line 20)... I'm just curious because I cant find why this happens.... I think it has something to do with the 2d array.. If I use a 1d array like in another game I wrote, it works... It also doesnt matter if I set the for loops for i and j to reach 2 or the length... Anyone think they can help or at least explain?