title: Drawing circles in 2d grid array in java
body: <p>I understand how to make 2d array grid. I experimented to put random numbers in it but i do not know how to draw them on jframe. For instance, 0 for red circle , 1 for green circle and so on. I need to figure out how represent them in grid manner too.</p>
  
  <pre><code>public class Game {
  
  
      public static void initGrid(){
          //clumn and row 4 x 4
          int col = 4;
          int row = 4;
  
          //initialize 2d grid array
          int[][] a = new int[row][col];
  
          Random rand = new Random();
  
          //for loop to fill it with random number
          for(int x = 0 ; x &lt; col ; x++) {
              for(int y = 0; y &lt; row; y++) {
                  a[x][y] = (int) rand.nextInt(4);
                  System.out.print(a[x][y]);
              }//inner for
              System.out.println();
          }//outer for
  
  
      }//method
  
  
      public static void main(String[] args){
          initGrid();
      }
  
  
  }
  </code></pre>
  
  <p>I understand JFrame and JPanel as far as drawing on empty canvas but not the way i want. I want to combine both code but my knowledge is limited.</p>
  
  <pre><code>    import java.awt.Color;
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.RenderingHints;
      import java.awt.geom.Ellipse2D;
      import javax.swing.JFrame;
      import javax.swing.JPanel;
  
    @SuppressWarnings("serial")
    public class Game2 extends JPanel{
  
      @Override
      public void paint(Graphics g){
          Graphics2D g2d = (Graphics2D) g;
          g2d.setColor(Color.RED);
          g2d.fillOval(0, 0, 30, 30);
          g2d.drawOval(0, 50, 30, 30);
          g2d.fillRect(50, 0, 30, 30);
          g2d.drawRect(50, 50, 30, 30);
  
          g2d.draw(new Ellipse2D.Double(0, 100, 30 ,30));
      }
  
       public static void main(String[] args){
          JFrame frame = new JFrame("Mini Tennis");
          frame.add(new Game2());
          frame.setSize(300, 300);
          frame.setVisible(true);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }
  } 
  </code></pre>