I'm currently developing a simple chessboard with Java ACM and I want to fill every second rectangle with a color but I don't know how to.
for (i = 0; i < 400; i += 50) {
for (j = 0; j < 400; j += 50) {
GRect rect = new GRect(100, 100, i, j);
add(rect);
}
}
I tried it with a if
statment, but i doesn't worked for me.
With your pretty minimal description, here is my solution.
Here is a tile-able representation. 1/2/3/4 represent "cases"
Assuming: i and j are dimensions of the chessboard, 50x50 is the size of a square.
Assuming: Constructor for GRect is (width, height, ipos, jpos), with top left rectangle coordinate system.
Assuming: Only making rectangles for black squares (cases 2 and 3)
Notice: cases 2 is when (i % 100 == 50) AND (
However, what you probably want is a checker board patter:
Note: no one has any idea what the constructor of GRect is, so i've made my best guess as to what to do.