edit: sorry for the big indentations, looks fine maximized though
Code:
for (int y= 0; y < HEIGHT; y++)
{
for (int x = 0; x < WIDTH; x++)
{
hide[x][y] = '0';
show[x][y] = new JButton(x +","+y);
show[x][y].addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
check(x,y); //problem here
}
});
show[x][y].setSize(500,100);
frame.getContentPane().add(show[x][y]);
}
}
error message (in eclipse IDE): "Cannot refer to a non-final variable x inside an inner class defined in a different method"
as the error message states, making the x and y variables 'final' solves the problem, however, if they are final then they wouldnt be able to be incremented on each iteration of the for loop.
if i put this inner class in its own file and then applied it here then i wouldnt be able to access the x and y variables. i could overload the mouseClicked function with parameter list (MouseEvent e, int x, int y) but it wouldnt get called.
i havent tried it but maybe making the variables either global or static would solve it, but i dont want to have to resort to that.
any help appreciated thanks