Using for loop to make multiple drawLine shapes : <p>I am making a star using a draw line. I want to run a for loop to expand a star into multiple stars in a grid-like pattern. I am fairly new to java and could use some help with my code. The gride pattern that I would like the stars to open up too isn't too specific as far as columns x rows go. even making 6 stars or 9 stars is fine, as long as they are in a grid-like pattern. </p>

<p>So far, I have the star drawn with drawLine. At one point I got two stars but they were to close to each other. When I run the code it looks like I have a whole bunch of stars sort of staggered on top of each other and being able to get two stars on Star Field, I would like to get more in such 5x6 pattern or something close. I believe I might be having a hard time computing the math in the for loops to get this to happen.</p>

<p>Should I run, multiple nested for loops or is there a way to do this with using a minimal amount of for loops?</p>

<pre><code>public static void drawFlag(int stars, int stripes, java.awt.Graphics 
g, int x, int y, int width, int height) {
// Sets backround rectangle color to white
g.setColor(Color.WHITE);
g.fillRect(x, y, width, height);

// Draw filled red rectangles *stripes*
int stripeHeight = height/stripes;
g.setColor(Color.RED);
int lastStripeDrawnY = 0;
// For loop runs red stripes
for (int i = y; i &lt; y + height - 2*stripeHeight; i = i + 2*stripeHeight) 
{ 
g.fillRect(x, i, width, stripeHeight);
lastStripeDrawnY = i;
}
    // expands strips across the rectangle
    int lastStripeY = lastStripeDrawnY+2*stripeHeight;
    int lastStripeHeight = y + height - lastStripeY;
    if (stripes%2 != 0) {
    g.fillRect(x, lastStripeY, width, lastStripeHeight);
            }   

    int stars1 = 15; 
    for (int cols = 1; cols  &lt;= stars1; cols++) {
    int rows = stars1/cols;
    if (cols &gt; rows &amp;&amp; cols &lt;2*rows &amp;&amp; cols*rows == stars1) {

}
}
            // Draws the starField
    int numberOfRedStripes = (int)Math.ceil(stripes/2.0);
    int starFieldHeight = numberOfRedStripes*stripeHeight;
    int starFieldWidth = starFieldHeight*width/height;
    g.setColor(Color.BLUE);
    g.fillRect(x, y, starFieldWidth, starFieldHeight);


for (int x1 = 0; x1+100 &lt;+ starFieldWidth-5; x1++) {
    if(x1/5*4 == stars) {
        drawStar(g,x1,y,50);
    for(int y1 = 0; y1 &lt;=starFieldHeight-5;y1++) {
                if(y1/4*2 == stars) {
        drawStar(g,x,y1,50);
            }
        }
    }
}
}
        // drawLine the star
public static void drawStar(java.awt.Graphics g, int x, int y, int size) 
{
g.setColor(Color.WHITE);
g.drawLine(x+size/2, y+size/6, x+4*size/5, y+5*size/6);
g.drawLine(x+4*size/5,y+5*size/6, x+size/6, y+2*size/5);
g.drawLine(x+size/6, y+2*size/5, x+5*size/6, y+2*size/5);
g.drawLine(x+5*size/6, y+2*size/5, x+size/5, y+5*size/6);
g.drawLine(x+size/5, y+5*size/6, x+size/2, y+size/6); 
}
} 
</code></pre>

<p>Expand one star into a checkered grid-like pattern.</p>
