title: How do I count the number of bombs in my Minesweeper code?
body: <p>So well I tried creating a simpler Minesweeper game and I encountered one main problem..
  I am not able to count the number of bombs and print it in a <code>JTextField</code>
  Any ideas as to how to count these as I'm setting a random value to check whether they are a bomb</p>
  
  <p>Tried counting it in the <code>ActionListener</code> but the bombs were counted only after the button was clicked.</p>
  
  <pre><code>     if(e.getSource()==b[i][j])
          {
              b[i][j].setVisible(false);
  
              tf[i][j].setVisible(true);
              int r1 = rand.nextInt(6);
              if(r1&gt;1)
              {
                  tf[i][j].setText("Safe");
                  tf[i][j].setBackground(Color.green);
  
              }
              else    
              {   count++;
                  tf[i][j].setText("Bomb");
                  tf[i][j].setBackground(Color.red);
                  f.setVisible(false);
                  restart.setVisible(true);
              }
          }
  </code></pre>