import java.awt.*;
import java.applet.*;
public class squares extends Applet
{
Dimension appletSize;
int xCoord = 0;
int yCoord = 0;
final int width = 30;
final int height = 30;
int xCount;
int yCount;
public void paint(Graphics g)
{
appletSize = this.getSize(); // get the dimensions of this applet
xCoord = 0; // start in the top left corner
yCoord = 0;
yCount = 1;
// loop over the applet height
do
{
if (yCount % 2 == 0)
{
xCount = 1;
}
else
{
xCount = 0;
}
xCoord = 0;
// loop over the applet width
do
{
if (xCount % 2 == 0)
{
g.setColor(Color.white);
}
else
{
g.setColor(Color.black);
}
g.fillRect(xCoord, yCoord, width, height);
xCoord = xCoord + width;
xCount = xCount + 1;
} while (xCoord < appletSize.width);
yCount = yCount + 1;
yCoord = yCoord + height;
} while (yCoord < appletSize.height);
}
} |