title: MineSweeper reveal neighbors help needed java
body: <p>I am currently working on a minesweeper program and i need a little help on revealing neighbors in it. Currently what my program can do for reveals is the following</p>
  
  <p>The 1 would be the button that was selected and the lines are what i need to be 
  filled in. Currently the buttons of around the button selected are what i can get to fill in.</p>
  
  <p>I can post code if necessary.</p>
  
  <p>Thanks for the help in advance. 
  <img src="https://i.stack.imgur.com/smOoj.jpg" alt="enter image description here"></p>
  
  <p>1 is a mine, 4 is a flagged spot on the array</p>
  
  <pre><code>public int findneighbors(int row, int col) {
        int count = 0;
      if (board[row][col] == 2)
          try {
              if (board[row][col + 1] == 1 || board[row][col + 1] == 4)
                  count ++;
          }
  
              catch( ArrayIndexOutOfBoundsException e)
              {
              }
          try {
          if (board[row + 1][col + 1] == 1 || board[row + 1][col + 1] == 4)
              count ++;
              }
          catch( ArrayIndexOutOfBoundsException e)
          {
          }
          try {
          if (board[row + 1][col - 1] == 1 || board[row + 1][col - 1] == 4)
              count ++;
              }
          catch( ArrayIndexOutOfBoundsException e)
          {
          }
          try {
              if (board[row - 1][col - 1] == 1 || board[row - 1][col - 1] == 4)
                  count ++;
                  }
              catch( ArrayIndexOutOfBoundsException e)
              {
              }
          try {
              if (board[row][col + 1] == 1 || board[row][col + 1] == 4)
                  count ++;
                  }
              catch( ArrayIndexOutOfBoundsException e)
              {
              }
          try {
              if (board[row + 1][col] == 1 || board[row + 1][col] == 4)
                  count ++;
                  }
              catch( ArrayIndexOutOfBoundsException e)
              {
              }
          try {
              if (board[row - 1][col] == 1 || board[row - 1][col] == 4)
                  count ++;
                  }
              catch( ArrayIndexOutOfBoundsException e)
              {
              }
          try {
              if (board[row][col - 1] == 1 || board[row][col - 1] == 4)
                  count ++;
                  }
              catch( ArrayIndexOutOfBoundsException e)
              {
              }
          try {
              if (board[row - 1][col + 1] == 1 || board[row - 1][col + 1] == 4)
                  count ++;
                  }
              catch( ArrayIndexOutOfBoundsException e)
              {
              }
  
      return count;
    }
  public int buttonFloodFill(int r, int c)
  {
      int loopCount = 0;
      int rowCount = 1;
      int colCount = 1;
      while (loopCount &lt; 1)
      {
          try {
      if (g.getFloodValue(r,c + colCount) == true) {
          board[r][c + colCount].setText(Integer.toString(g.findneighbors(r,c + colCount)));
          board[r][c + colCount].setEnabled(false);
      }
          }
      catch( ArrayIndexOutOfBoundsException e)
      {
      }
      try {
      if (g.getFloodValue(r,c - colCount) == true) {
          board[r][c - colCount].setText(Integer.toString(g.findneighbors(r,c - colCount)));
          board[r][c - colCount].setEnabled(false);
      }
      }
  catch( ArrayIndexOutOfBoundsException e)
  {
  }
      try {
      if (g.getFloodValue(r + rowCount,c + colCount) == true) {
          board[r + rowCount][c + colCount].setText(Integer.toString(g.findneighbors(r + rowCount,c + colCount)));
          board[r + rowCount][c + colCount].setEnabled(false);
      }
      }
  catch( ArrayIndexOutOfBoundsException e)
  {
  }
      try {
      if (g.getFloodValue(r + rowCount,c - colCount) == true) {
          board[r + rowCount][c - colCount].setText(Integer.toString(g.findneighbors(r + rowCount,c - colCount)));
          board[r + rowCount][c - colCount].setEnabled(false);
      }
      }
  catch( ArrayIndexOutOfBoundsException e)
  {
  }
      try {
      if (g.getFloodValue(r - rowCount,c - colCount) == true) {
          board[r - rowCount][c - colCount].setText(Integer.toString(g.findneighbors(r - rowCount,c - colCount)));
          board[r - rowCount][c - colCount].setEnabled(false);
          }
      }
  catch( ArrayIndexOutOfBoundsException e)
  {
  }
      try {
      if (g.getFloodValue(r - rowCount,c + colCount) == true) {
          board[r - rowCount][c + colCount].setText(Integer.toString(g.findneighbors(r - rowCount,c + colCount)));
          board[r - rowCount][c + colCount].setEnabled(false);
      }
      }
  catch( ArrayIndexOutOfBoundsException e)
  {
  }
      try {
      if (g.getFloodValue(r - rowCount,c) == true) {
          board[r - rowCount][c].setText(Integer.toString(g.findneighbors(r - rowCount,c)));
          board[r - rowCount][c].setEnabled(false);
      }
      }
  catch( ArrayIndexOutOfBoundsException e)
  {
  }
      try {
      if (g.getFloodValue(r + rowCount,c) == true) {
          board[r + rowCount][c].setText(Integer.toString(g.findneighbors(r+ rowCount,c)));
          board[r + rowCount][c].setEnabled(false);
      }
      }
  catch( ArrayIndexOutOfBoundsException e)
  {
  }
      rowCount ++;
      colCount ++;
      loopCount ++;
  
      }
      return 0;
  }
  </code></pre>