I thought everything was correct, but I keep getting an error "cannot find symbol- variable x" The line in question is line 34. I have provided all code.
ColorTest Subclass of World
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class ColorTest here.
* @author (your name)
* @version (a version number or a date)
*/
public class ColorTest extends World
{
/**
* Constructor for objects of class ColorTest.
*
*/
public ColorTest()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(400, 400, 1);
boolean black = true;
for (int x = 0; x < 8; x++)
{
if(black) //alternate colors at the start of each column
black = false;
else
black = true;
}
for (int y = 0; y < 8; y++)
{
if(black) //alternate the colors
{
ColorPatch blackSquare = new ColorPatch (0,0,0);
addObject(blackSquare, x*50 + 25, y*50 + 25);
black = false;
}
else
{
ColorPatch redSquare = new ColorPatch(255,0,0);
addObject(redSquare, x*50 + 25, y * 50 + 25);
black = true;
}
}
}}
Actor ColorPatch
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class ColorPatch here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ColorPatch extends Actor
{
/**
* Act - do whatever the ColorPatch wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public ColorPatch(int r, int g, int b)
{
GreenfootImage img = new GreenfootImage(50, 50);
img.setColor (new java.awt.Color(r,g,b));
img.fill();
setImage(img);
}
}
