title: Nested loops when using draw methods, having trouble figuring out how to set it up right
body: <p>I need help figuring out how to draw a checkerboard/quilt like pattern in a nested for loop using draw method in java. My Lab assignment reads as follows. 
  You must create a QuiltPattern Class and declare two objects of that class. The constructor for this class will accept a parameter that sets a characteristic of the object (like the color), Alternate those objects when drawing the quilt. Make sure that your quilt contains at least 5 blocks across and 7 down. Your QuiltPattern class should include a method called Draw() that draws the pattern on the screen at a specific location. You must use nested loops to draw the quilt. 
  I have everything mostly written, but I'm having trouble getting a quiltlike/checkerboard like object drawn. I can't seem to get it to line up and so far I only have two rows that are offset. Any help or suggestions to get this to work in a nested loop would be much appreciated. I've been trying to find something similar to this and I haven't have much luck. What am I doing wrong? </p>
  
  <p>This is my QuiltPanel:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class QuiltPanel extends JPanel
  {
      int x = 0, y = 0, count = 0;
  
  private Quilt squareOne, squareTwo;
  
  public QuiltPanel()
  {
      squareOne = new Quilt(25, Color.blue, x+50, y);
      squareTwo = new Quilt(25, Color.green, x+25, y);
  
      setPreferredSize(new Dimension(750, 500));
      setBackground(Color.black);
  
  }
  public void paintComponent(Graphics page)
      {
          super.paintComponent(page);
          for ( count = 0; count &lt;= 10; count = count+1)
          {   if ( count % 2 == 0)
              {   if ( count &lt;= 5)
                  {   squareOne.draw(page);
                      squareOne = new Quilt(25, Color.blue, x, y);
  
                  }
                  else
                  {   squareOne.draw(page);
                      squareOne = new Quilt(25, Color.blue, x, y+25);
  
                  }
  
              }
              else
              {   if ( count &lt;= 5)
                  {   squareTwo.draw(page);
                      squareTwo = new Quilt(25, Color.green, x, y);
  
                  }
                  else
                  {   squareTwo.draw(page);
                      squareTwo = new Quilt(25, Color.green, x, y+25);
  
                  }
  
              }
              x=x+25;
          }
     }
  }
  </code></pre>
  
  <p>This is my Quilt Class:</p>
  
  <pre><code>import java.awt.*;
  
  public class Quilt
  
  {
    private int height, width, x, y;
    private Color color;
  
  public Quilt(int size, Color newColor, int upperX, int upperY)
  {
      width = size;
      height = size;
      color = newColor;
      x = upperX;
      y = upperY;
  
  }
  
  public void draw(Graphics page)
  {
      page.setColor(color);
      page.fillRect(x, y, width, height);
  }
  
  public void setHeight(int size)
  {
      height = size;
  }
  
  public void setWidth(int size)
  {
      width = size;
  }
  
  public void setColor(Color newColor)
  {
      color = newColor;
  }
  
  public void setX(int upperX)
  {
      x = upperX;
  }
  
  public void setY(int upperY)
  {
      y = upperY;
  }
  
  public int getHeight()
  {
      return height;
  }
  
  public int getWidth()
  {
      return width;
  }
  
  public Color getColor()
  {
      return color;
  }
  
  public int getX()
  {
      return x;
  }
  
  public int getY()
  {
      return y;
  }
  }
  </code></pre>
  
  <p>And if you need it my QuiltPattern (JFrame):</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class QuiltPattern
  {
  public static void main(String[] args)
  {
      JFrame frame = new JFrame("QuiltPattern");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      frame.getContentPane().add(new QuiltPanel());
      frame.getContentPane().add(new QuiltPanel());
  
      frame.pack();
      frame.setVisible(true);
  }
  }
  </code></pre>