Reputation: 1
I'm trying to make a drawing panel that draws little circles with numbers in it, going from 0 to 9. However, the for loop, for one reason or another, keeps skipping 0. I've tried setting i to -1, but that doesn't change anything. Conversely when I set the condition to i < 11, it draws all numbers from 1 to 10.
Here's the code so far:
`
// Draws boxed ovals using a while loop.
import java.awt.*;
public class DrawLoop
{
public static void main(String[] args)
{
DrawingPanel panel = new DrawingPanel(502, 252);
panel.setBackground(Color.CYAN);
Graphics g = panel.getGraphics();
String iValue = "";
int sizeX = 50; // size of boxes
int sizeY = 25;
int i;
for (i = 0; i < 10; i++) { // start at i = 0
int cornerX = i*50; // calculate upper left corner
int cornerY = i*25;
g.setColor(Color.WHITE);
g.fillOval(cornerX + 5, cornerY + 5, sizeX-10, sizeY-10);
g.setColor(Color.BLACK);
g.drawRect(cornerX, cornerY, sizeX, sizeY);
iValue = "" + i;
g.drawString(iValue, cornerX - 29, cornerY - 8);
}
}
}
`
Tried to make a drawing panel that drew numbers from 0-9, loop skips 0 and only does 1-9.
Upvotes: 0
Views: 34