Constructing a Quilt
<p>For this problem, you are going to create a class PatchworkQuilt which has a constructor and a draw method. Our quilt will have solid squares.</p>

<p>The constructor takes three parameters: the upper left x and the top y coordinates of the starting location of the quilt and the width of a square .All PatchWorkQuilts are 8 squares wide by 8 squares high. The colors of the squares alternate. The first row is black, yellow, red, blue and then repeats. The second row is yellow, red, blue and then repeats. And so on. Look at the screen shot. You must use nested loops. Provide a draw method that takes a Graphics2D object as argument</p>

<p>And we need to create a PatchworkQuilt class, along with these two other class, which are given. I have no idea how to approach this, or go about it.</p>

<p>So far this is all I got, and I'm pretty sure I'm wrong</p>

<p>PatchworkQuilt.java</p>

<pre><code>import java.awt.Rectangle;
import java.awt.Graphics2D;
import java.awt.Graphics;
public class PatchworkQuilt {
    private int xleft;
    private int ytop;
    private int zwidth;
}

public PatchworkQuilt(int x, int y, int z)  {
    xleft = x;
    ytop = y;
    zwidth = z;
}

public void draw(Graphics2D g2) {
    Rectangle box = new Rectangle(10, 10, 10, 10);
    g2.draw(box);
    }
}
</code></pre>

<p>And these are the two files that PatchworkQuit.java need to associate with.
PatchworkQuiltComponent.java</p>

<pre><code>import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;
public class PatchworkQuiltComponent extends JComponent
{
    public void paintComponent(Graphics g)
    {
        Graphics2D g2 = (Graphics2D) g;
        PatchworkQuilt quilt = new PatchworkQuilt(50, 50, 50);
        quilt.draw(g2);
    }
}
</code></pre>

<p>PatchworkQuiltViewer.java</p>

<pre><code>import javax.swing.JFrame;
public class PatchworkQuiltViewer
{
    public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
PatchworkQuiltComponent component = new PatchworkQuiltComponent();
frame.add(component);
frame.setVisible(true);
    }
}
</code></pre>

<p>Final output should be this</p>

<p><a href="http://i566.photobucket.com/albums/ss107/iQuoc/patchwork.png" rel="nofollow">http://i566.photobucket.com/albums/ss107/iQuoc/patchwork.png</a></p>
