title: Drawing graphics in Java
body: <p>I am trying to draw a circle in side a square and having multiple square circles in java. I am almost done but my output isn't coming out as I wanted to. The picture is what I am trying to do but it's not working out.</p>
  
  <p><img src="https://i.stack.imgur.com/kge2X.png" alt="This is what I am trying to draw[1]">
  Here is my code:</p>
  
  <pre><code>a.awt.*;
  
  public class SquaredCircles {
      public static final int WIDTH=400;
      public static final int HEIGHT=400;
  
      public static void main (String[] args) {
          DrawingPanel panel = new DrawingPanel(WIDTH,HEIGHT);
          Graphics g = panel.getGraphics ();
  
          panel.setBackground(new Color(0, 255, 255 ) );
  
          int x = 0;
          int y = 0;
          int size = 100;
          int rows = 5;
          int numSquares = 1;
  
          drawManySquares ( g, numSquares, x, y, size, rows );
  
          x = 10;
          y = 120;
          size = 24;
          rows = 4;
          numSquares = 4;
  
          drawManySquares( g, numSquares, x, y, size, rows );
  
          x = 150;
          y = 20;
          size = 40;
          rows = 6;
          numSquares = 5;
  
          drawManySquares( g, numSquares, x, y, size, rows );
  
          x = 130;
          y = 275;
          size = 36;
          rows = 3;
          numSquares = 3;
  
          drawManySquares( g, numSquares, x, y, size, rows );
      }
  
      public static void drawManySquares( Graphics g, int numSquares, int x, int y, int size, int rows ) {
          for ( int i = 0; i &lt; numSquares; i++ ) {
              for ( int j = 0; j &lt; numSquares; j++ ) {
                  drawOneSquare( g, x + i  size, y + j  size, size, rows );
              }
          }
      }
  
      public static void drawOneSquare( Graphics g, int x, int y, int size, int rows ) {
          g.setColor ( Color.GREEN);
          g.fillRect(x , y, size, size);
  
          g.setColor ( Color.YELLOW);
          g.fillOval ( x, y, size, size);
  
          g.setColor ( Color.BLACK);
          g.drawLine(size / 2, x, size / 2, size);
          g.setColor ( Color.BLACK);
          g.drawLine(x, size / 2, size, size / 2);
  
          for (int i = 0; i &lt;= rows; i = i + 1) {
              g.setColor ( Color.BLACK);
              g.drawOval(x + (i* (size/rows)), y+ (i*(size/rows)), size - (i*(size/rows +10   )) , size - (i*(size/rows +10)));
          }
      }
  }
  </code></pre>