import java.awt.*;

public class ShadeComponent extends java.awt.Component
{
    int r, g, b;
    Color c;
    Image i;
    
    public ShadeComponent(int _r, int _g, int _b)
    {
        r = _r;
        g = _g;
        b = _b;
        c = new Color(r, g, b);
        i = null;
    }
    
    public int getRed()
    {
        return r;
    }

    public int getGreen()
    {
        return g;
    }

    public int getBlue()
    {
        return b;
    }

    public void setColor(int _r, int _g, int _b)
    {
        if (r != _r || g != _g || b != _b)
        {
            r = _r;
            g = _g;
            b = _b;
            c = new Color(r, g, b);
            this.repaint();
        }
    }
    
    public void paint(Graphics g)
    {
        Graphics g2; 
        
        if ( i == null ||
             ( !( i.getWidth(this)  == size().width  &&
                  i.getHeight(this) == size().height ) ) )
        {
            i = createImage(size().width, size().height);
        }

        g2 = i.getGraphics();
        g2.setColor(c);
        g2.fillRect(0, 0, size().width, size().height);
        g2.dispose();

        g.drawImage(i, 0, 0, null); 
    }
    
    public void update(Graphics g)
    {
        paint(g);
    }
}