// declare and initialise x2Coord constant
stopValue = (int)(Math.random() * 20 + 1); // generate a random termination value
counter = 1; // initialise the loop control variable
while (counter <= stopValue) // loop 10 times
{
if (counter % 2 == 0) // if counter is an even number
{
g.setColor(Color.blue); // set drawing colour blue
}
else // this is an odd number
{
g.setColor(Color.red); // set drawing colour red
}
g.drawLine(x1Coord, y1Coord, x2Coord, counter * 10);
counter = counter + 1; // increment the loop control variable
}
g.drawString(stopValue + " Nice lines", 20, 260);