title: Making a simple Mine Sweeper game in Java
body: <p>I'm working on creating a simple mine sweeper game in java using JButtons. So far I have a code that creates a 20x20 grid of JButtons, but I am unsure of how I can get my bombs randomly assigned to multimple JButtons durring the game. </p>
  
  <p>Here is what I have written so far:</p>
  
  <p><strong>MineSweeper Class:</strong></p>
  
  <pre><code>import javax.swing.*;
  import java.awt.GridLayout;
  public class MineSweeper extends JFrame {
  JPanel p = new JPanel();
  bombButton points[][]= new bombButton[20][20];
  
  public static void main(String args[]){
      new MineSweeper();
  }
  
  public MineSweeper(){
      super("Mine Sweeper Version: Beta");
      setSize(400,400);
      setResizable(false);
      setDefaultCloseOperation(EXIT_ON_CLOSE);
  
      p.setLayout(new GridLayout(20,20));
      int y=0;
      int counter=0;
      while(counter&lt;20){   
          for(int x=0;x&lt;20;x++){
              points[x][y] = new bombButton();
              p.add(points[x][y]);
          }
          y++;
          counter++;
      }
      add(p);
  
      setVisible(true);
  }
  }
  </code></pre>
  
  <p><strong>bombButton Class:</strong></p>
  
  <pre><code>import javax.swing.*;
  import java.awt.event.ActionListener;
  import java.awt.event.ActionEvent;
  import java.net.URL;
  
  public class bombButton extends JButton implements ActionListener {
  ImageIcon Bomb,zero,one,two,three,four,five,six,seven,eight;
  
  public bombButton(){
      URL imageBomb = getClass().getResource("Bomb.png");
      Bomb= new ImageIcon(imageBomb);
  
      URL imageZero = getClass().getResource("0.jpg");
      zero= new ImageIcon(imageZero);
  
      URL imageOne = getClass().getResource("1.jpg");
      one= new ImageIcon(imageOne);
  
      URL imageTwo = getClass().getResource("2.jpg");
      two= new ImageIcon(imageTwo);
  
      URL imageThree = getClass().getResource("3.jpg");
      three= new ImageIcon(imageThree);
  
      URL imageFour = getClass().getResource("4.jpg");
      four= new ImageIcon(imageFour);
  
      URL imageFive = getClass().getResource("5.jpg");
      five= new ImageIcon(imageFive);
  
      URL imageSix = getClass().getResource("6.jpg");
      six= new ImageIcon(imageSix);
  
      URL imageSeven = getClass().getResource("7.jpg");
      seven= new ImageIcon(imageSeven);
  
      URL imageEight = getClass().getResource("8.jpg");
      eight= new ImageIcon(imageEight);
  
      this.addActionListener(this);
  }
  
  public void actionPerformed(ActionEvent e){
      switch(){
          case 0:
              setIcon(null);
              break;
          case 1:
              setIcon(Bomb);
              break;
          case 2:
              setIcon(one);
              break;
          case 3:
              setIcon(two);
              break;
          case 4:
              setIcon(three);
              break;
          case 5:
              setIcon(four);
              break;
          case 6:
              setIcon(five);
              break;
          case 7:
              setIcon(six);
              break;
          case 8:
              setIcon(seven);
              break;    
          case 9:
              setIcon(eight);
              break;    
      }
  }
  
  int randomWithRange(int min, int max)
  {
      int range = Math.abs(max - min) + 1;     
      return (int)(Math.random() * range) + (min &lt;= max ? min : max);
  }
  }
  </code></pre>
  
  <p>As you can see I already have a randomizer set up, I just don't know how I should implement it. Should I use (X,Y) cordinates? How do I assign my bombs to random JButtons?</p>
  
  <p>Thnak you to all in advance!</p>