// Grid.java
// Janine Bouyssounouse 2/24/07
// Makes a grid for multiplication
import java.awt.*;
import java.util.Random;
import java.awt.geom.*;

public class Grid
{
private static final double CELL_SIZE = 40;
private static final double SPACE = 50;
private static final double GRIDX = 50;
private static final double GRIDY = 50;

private double gridWidth;
private double gridHeight;
private double numStart;
private String numberText;
private int numColumns;
private int numRows;

public void draw(Graphics2D g2)
{

numColumns = getRandom();
numRows = getRandom();

gridWidth = numColumns * CELL_SIZE;
gridHeight = numRows * CELL_SIZE;

for(int i = 0; i <= numRows ; i++)
{
//horizontal line
Point2D.Double p1 = new Point2D.Double(GRIDX, (GRIDY + CELL_SIZE * i));
Point2D.Double p2 = new Point2D.Double((GRIDX + gridWidth), (GRIDY + CELL_SIZE * i));
Line2D.Double line = new Line2D.Double(p1, p2);
g2.draw(line);
}

for(int i = 0; i <= numColumns ; i++)
{
//vertical line
Point2D.Double p1 = new Point2D.Double((GRIDX + CELL_SIZE * i), GRIDY);
Point2D.Double p2 = new Point2D.Double((GRIDX + CELL_SIZE * i), (GRIDY + gridHeight));
Line2D.Double line = new Line2D.Double(p1, p2);
g2.draw(line);
}

numStart = numRows * CELL_SIZE + SPACE + GRIDY;

Font medFont = new Font("SanSerif", Font.BOLD, 24);

g2.setFont(medFont);

g2.setColor(Color.blue);

numberText = numRows + " x " + numColumns + " = " + getAnswer();

g2.drawString(numberText, (float)GRIDX, (float)numStart);
} // end method draw

public int getRandom()
{
Random generator = new Random();

int random = 1 + generator.nextInt(9);

return random;
} // end method getRandom

public int getAnswer()
{
return numRows * numColumns;
} // end method getAnswer
} // end class Grid

-----------------------------------------------------------------

// GridApplet.java
// Janine Bouyssounouse 2/24/07
import java.applet.*;
import java.awt.*;

public class GridApplet extends Applet
{
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;

Grid myGrid = new Grid();

myGrid.draw(g2);

} // end paint
} // end class GridApplet