If I run this code I get the AWT-EventQueue-0" java.lang.StackOverflowError and firePropertyChange errors. I am working on a java GUI based game. If a button containing 0 count is clicked, I have to find all adjacent cells containing zero until I find no more adjacent 0 cells. Than I am supposed to reveal the non 0 adjacent cells
public void reveal_zero_cell(int r, int c)
{
if(myGrid.getCountAtLocation(r, c) != 0)
{
board[r][c].setText(Integer.toString(myGrid.getCountAtLocation(r, c))); //up
if(board[r][c].isEnabled()) {
cell_checked++;
board[r][c].setEnabled(false);
}
if( (r>0) && !(myGrid.isBombAtLocation(r-1, c)))
{
board[r-1][c].setText(Integer.toString(myGrid.getCountAtLocation(r-1, c))); //up
if(board[r-1][c].isEnabled()) {
cell_checked++;
board[r-1][c].setEnabled(false);
}
}
if((r+1 < NUM_ROWS) && !(myGrid.isBombAtLocation(r+1, c)))
{
board[r+1][c].setText(Integer.toString(myGrid.getCountAtLocation(r+1, c))); //down
if(board[r+1][c].isEnabled()) {
cell_checked++;
board[r+1][c].setEnabled(false);
}
}
if((c+1 <NUM_COLS) && !(myGrid.isBombAtLocation(r, c+1)))
{
board[r][c+1].setText(Integer.toString(myGrid.getCountAtLocation(r, c+1))); //right
if(board[r][c+1].isEnabled()) {
cell_checked++;
board[r][c+1].setEnabled(false);
}
}
if((c >0 ) && !(myGrid.isBombAtLocation(r, c-1)) )
{
board[r][c-1].setText(Integer.toString(myGrid.getCountAtLocation(r, c-1))); //left
if(board[r][c-1].isEnabled()) {
cell_checked++;
board[r][c-1].setEnabled(false);
}
}
if((r > 0 && c>0)&& !(myGrid.isBombAtLocation(r-1, c-1)))
{
board[r-1][c-1].setText(Integer.toString(myGrid.getCountAtLocation(r-1, c-1))); // main dia left corner
if(board[r-1][c-1].isEnabled()) {
cell_checked++;
board[r-1][c-1].setEnabled(false);
}
}
if((r + 1 < NUM_ROWS) &&(c+1 < NUM_COLS) && !(myGrid.isBombAtLocation(r+1, c+1)))
{
board[r+1][c+1].setText(Integer.toString(myGrid.getCountAtLocation(r+1, c+1))); //main dia right corner
if(board[r+1][c+1].isEnabled()) {
cell_checked++;
board[r+1][c+1].setEnabled(false);
}
}
if((r + 1 < NUM_ROWS) &&(c > 0) && !(myGrid.isBombAtLocation(r+1, c-1)))
{
board[r+1][c-1].setText(Integer.toString(myGrid.getCountAtLocation(r+1, c-1))); //2nd dia left corner
if(board[r+1][c-1].isEnabled()) {
cell_checked++;
board[r+1][c-1].setEnabled(false);
}
}
if((r > 0 ) &&(c +1 < NUM_COLS) && !(myGrid.isBombAtLocation(r-1, c+1)))
{
board[r-1][c+1].setText(Integer.toString(myGrid.getCountAtLocation(r-1, c+1))); //2nd dia right corner
if(board[r-1][c+1].isEnabled()) {
cell_checked++;
board[r-1][c+1].setEnabled(false);
}
return;
}
}
else {
if(myGrid.getCountAtLocation(r, c) == 0)
{
board[r][c].setText(Integer.toString(myGrid.getCountAtLocation(r, c)));
if(board[r][c].isEnabled()) {
cell_checked++;
board[r][c].setEnabled(false);
}
}
if( (r>0) && myGrid.getCountAtLocation(r-1, c) == 0)
{
board[r-1][c].setText(Integer.toString(myGrid.getCountAtLocation(r-1, c))); //up
if(board[r-1][c].isEnabled()) {
cell_checked++;
board[r-1][c].setEnabled(false);
}
reveal_zero_cell(r-1,c);
}
if((r+1 < NUM_ROWS) && myGrid.getCountAtLocation(r+1, c) == 0)
{
board[r+1][c].setText(Integer.toString(myGrid.getCountAtLocation(r+1, c))); //down
if(board[r+1][c].isEnabled()) {
cell_checked++;
board[r+1][c].setEnabled(false);
}
reveal_zero_cell(r+1,c);
}
if((c+1 <NUM_COLS) && myGrid.getCountAtLocation(r, c+1) == 0)
{
board[r][c+1].setText(Integer.toString(myGrid.getCountAtLocation(r, c+1))); //right
if(board[r][c+1].isEnabled()) {
cell_checked++;
board[r][c+1].setEnabled(false);
}
reveal_zero_cell(r,c+1);
}
if((c >0 ) && myGrid.getCountAtLocation(r, c-1) == 0)
{
board[r][c-1].setText(Integer.toString(myGrid.getCountAtLocation(r, c-1))); //left
if(board[r][c-1].isEnabled()) {
cell_checked++;
board[r][c-1].setEnabled(false);
}
reveal_zero_cell(r,c-1);
}
if((r > 0 && c>0) && myGrid.getCountAtLocation(r-1, c-1) == 0)
{
board[r-1][c-1].setText(Integer.toString(myGrid.getCountAtLocation(r-1, c-1))); // main dia left corner
if(board[r-1][c-1].isEnabled()) {
cell_checked++;
board[r-1][c-1].setEnabled(false);
}
reveal_zero_cell(r-1,c-1);
}
if((r + 1 < NUM_ROWS) && (c +1 < NUM_COLS) && myGrid.getCountAtLocation(r+1, c+1) == 0 )
{
board[r+1][c+1].setText(Integer.toString(myGrid.getCountAtLocation(r+1, c+1))); //main dia right corner
if(board[r+1][c+1].isEnabled()) {
cell_checked++;
board[r+1][c+1].setEnabled(false);
}
reveal_zero_cell(r+1,c+1);
}
if((r + 1 < NUM_ROWS) &&(c > 0) && myGrid.getCountAtLocation(r+1, c-1) == 0)
{
board[r+1][c-1].setText(Integer.toString(myGrid.getCountAtLocation(r+1, c-1))); //2nd dia left corner
if(board[r+1][c-1].isEnabled()) {
cell_checked++;
board[r+1][c-1].setEnabled(false);
}
reveal_zero_cell(r+1,c-1);
}
if((r > 0 ) &&(c +1 < NUM_COLS) && myGrid.getCountAtLocation(r-1, c+1) == 0)
{
board[r-1][c+1].setText(Integer.toString(myGrid.getCountAtLocation(r-1, c+1))); //2nd dia right corner
if(board[r-1][c+1].isEnabled()) {
cell_checked++;
board[r-1][c+1].setEnabled(false);
}
reveal_zero_cell(r-1,c+1);
}
}
}