My problem is I need to use only one drawLine. I couldn't figure out how am I supposed to make changes at the same time in x and y while not messing with one and another. I can't use a rectangle.
int x = 25;
int y = 25;
for (int i = 0; i <=8; i++) {
g2d.drawLine(x, y, x+160, y);
y+=20;
}
x = 25;
y = 25;
for (int i = 0; i <=8; i++) {
g2d.drawLine(x, y, x, y+160);
x+=20;
}
forloop, varying X in the outer loop and varying Y in the inner loop.int startX = 25, startY = 25, endX = startX + 160, endY = startY + 160; for (int i = 0; i <= 17; i++) { int h = i & 1, v = h ^ 1, x = startX + v * (i>>1) * 20, y = startY + h * (i>>1) * 20; g2d.drawLine(x, y, x * v + endX * h, y * h + endY * v); }As said, I’d stick to the two loops. And well, to me, this grid doesn’t look like a backgammon board, not even remotely.