// Colors\Colors.java - show how to use predefined and user-defined colors

import java.awt.*;
import java.applet.*;
import java.math.*;

public class Colors extends Applet {

    // Convert degress to radians
    final static private double CVT = Math.PI / 180.0;
    static private int width;
    static private int height;

    public void init() {
        width  = Integer.parseInt(getParameter("width"));
        height = Integer.parseInt(getParameter("height"));
        setBackground(Color.darkGray);
    }

    public void paint(Graphics g) {
	    // Prevent resizing
        resize(width, height);
        // Draw the shield; insert the legend
        g.setColor(Color.BLACK);
        g.fillRect(250, 30, 80, 30);
        g.setColor(Color.white);
        g.drawRect(250, 30, 80, 30);
        g.drawRect(249, 29, 82, 32);
        g.setColor(Color.CYAN);
        g.drawString("A Sine Wave", 257, 50);

        // Draw the sine wave -- 0..360 degrees; vary the color
        for (int degrees = 0; degrees <= 360; degrees++) {
            g.setColor(new Color(0, (4 * degrees) % 256, 0));
            g.drawLine(degrees + 20, 110,
                       degrees + 20, 110 - (int) (100 * Math.sin(CVT * degrees)));
        }
    }

} // end class Colors
