import java.lang.Object; import java.awt.Color; import java.awt.Graphics; public class Square { private int number; private int left; private int top; private int width; private int height; private Color color; private boolean visited; public Square(int _left, int _top, int _width, int _height, Color _color) { number = 0; left = _left; top = _top; width = _width; height = _height; color = _color; visited = false; } public int number() { return number;} public int left() { return left;} public int top() { return top;} public int width() { return width;} public int height() { return height;} public Color color() { return color;} public boolean visited() { return visited;} public void Visit(int _number) { number = _number; visited = true; } public void UndoVisit() { number = 0; visited = false; } public void Clear() { number = 0; visited = false; } public void Draw(Graphics _g) { if ((width != 0) && (height != 0)) { _g.setColor(color); _g.fillRect(left, top, width, height); if (number != 0) { _g.setColor(Color.red); // draw number int number_left = (left/width)*width + width * 1/8; int number_top = (top/height)*height + height* 6/8; _g.drawString(Integer.toString(number), number_left, number_top); } } } }