/*
	Uses infor from form data in a HTML Document,
	together with Javascript to draw lines
*/

import java.awt.*;
import java.applet.Applet;

public class Drawn3 extends Applet
{
	// globals
	String Title;
	int x[];
	int y[];
	Object color[];
	int n;
	int yMax=200;
	
	// the code...
	public  void init() {
	    String s;
		Title = new String("Title");
		s = getParameter("n");
		
		if ( s == null) {
			n=0;
		} else {
			n=Integer.parseInt(s);
		}
		// set up the array of points
		x = new int[n];
		y = new int[n];
		color = new Color[n];
		
		//find out the vertical limit to adjust for co-ords
		s = getParameter("ymax");
		if ( s == null) {
			yMax=200; //default
		} else {
			yMax=Integer.parseInt(s);
		}
		repaint();
	}
	
	public void paint( Graphics g ) {
		g.drawString(Title, 30, 30 );
		g.drawString("A", x[0],y[0]);
		g.drawString("B", x[1],y[1]);
		g.drawString("C", x[2],y[2]);
		for (int i=0; i< n-1; i++) {
			g.setColor((Color)(color[i]));
			g.drawLine(x[i], y[i], x[i+1], y[i+1]);
			g.setColor(Color.red);
			g.fillOval(x[i]-1, y[i]-1, 3, 3);
			g.fillOval(x[i+1]-1, y[i+1]-1, 3, 3);
		}
		
	}
	public void setString(String aString) {
		Title = aString;
		repaint();
	}
	public void setPoint( int i, float xpt, float ypt, String colour) {
		x[i-1] = 2+(int)(.9*xpt);
		y[i-1] = 2+yMax-(int)(.9*ypt);
		if (colour != null) {
		 if (colour.equals("red")) {
                    color[i-1] = Color.red;
                } else if (colour.equals("green")) {
                    color[i-1] = Color.green;
                } else if (colour.equals("blue")) {
                    color[i-1] = Color.blue;
                } else if (colour.equals("pink")) {
                    color[i-1] = Color.pink;
                } else if (colour.equals("orange")) {
                    color[i-1] = Color.orange;
                } else if (colour.equals("magenta")) {
                    color[i-1] = Color.magenta;
                } else if (colour.equals("cyan")) {
                    color[i-1] = Color.cyan;
                } else if (colour.equals("white")) {
                    color[i-1] = Color.white;
                } else if (colour.equals("yellow")) {
                    color[i-1] = Color.yellow;
                } else if (colour.equals("gray")) {
                    color[i-1] = Color.gray;
                } else if (colour.equals("darkGray")) {
                    color[i-1] = Color.darkGray;
                } else {
                    color[i-1] = Color.black;
                }
            } else {
                color[i-1] = Color.black;
            }
		repaint();
	}

}
