import java.awt.*;

/**
 * A view of a single square on a chess board.
 *
 * @author Jim Glenn
 * @version 0.1 12/3/2002
 */

public class SquareView extends Canvas
{
    /**
     * The string to appear on this square.
     */

    private String piece;

    /**
     * Creates a new empty square with a black background and white foreground
     */

    public SquareView()
    {
	setBackground(Color.black);
	setForeground(Color.white);
	piece = " ";
    }

    /**
     * Draws this square.
     *
     * @param g the graphics context to draw on
     */

    public void paint(Graphics g)
    {
	g.setFont(new Font("SansSerif", Font.BOLD, getHeight() / 2));
	g.setColor(getBackground());
	g.fillRect(0, 0, getWidth(), getHeight());
	g.setColor(getForeground());
	g.drawString(piece, getWidth() / 4, getHeight() * 3 / 4);
    }

    /**
     * Sets the piece on this square.
     *
     * @param s the new piece
     */

    public void setText(String s)
    {
	piece = s;
	repaint();
    }
}

