/* a simple program to create and display a series of lines, text, and shapes. 
   Can be run as either an applet or an application - written by Matt Ward */

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

public class VectorTest extends Applet {

    static final int width = 400; // constant dimensions for frame
    static final int height = 400;
    private Color red, green, blue, custom;
    private Polygon p;

// just create a few colors to draw in, and set up a polygon with points
    public void init()  {
        red = Color.red;
        green = Color.green;
        blue = Color.blue;
        custom = new Color(250, 0, 250);
        p = new Polygon();
        p.addPoint(200, 20);
        p.addPoint(250, 25);
        p.addPoint(200, 30);
        }  //end init()

// draw a bunch of primitives
    public void paint(Graphics g) {
        int x1, x2, y1, y2;
// a red box
        g.setColor(red);
        g.drawRect(10,15,100,100);
// a green rounded, filled box
        g.setColor(green);
        g.fillRoundRect(110,115,200,200,25,25);
// a blue string
        g.setColor(blue);
        g.drawString("Some Sample Text", 10, 250);
// 50 random purple lines
        g.setColor(custom);
        for(int i = 0;i < 50;i++)  {
	    x1 = (int) (Math.random() * width);
	    x2 = (int) (Math.random() * width);
	    y1 = (int) (Math.random() * height);
	    y2 = (int) (Math.random() * height);
            g.drawLine(x1, y1, x2, y2);
	    }
// a purple polygon
        g.fillPolygon(p);
        }  // end paint()

//  the entry point for the application - just create a frame and insert applet
    public static void main(String args[]) {
	VectorFrame f = new VectorFrame("VectorTest");
        f.setSize(width, height);
	f.show();
        }  // end main()
    }  // end VectorTest class

// extend Frame class to allow graceful window closing (copied from 
// Graphic Java book)
class VectorFrame extends Frame {
    public VectorFrame(String frameTitle)  {
        super(frameTitle);
        VectorTest app = new VectorTest();
        app.init();
        app.start();
        add(app, "Center");
        addWindowListener(new WindowAdapter()   {
           public void windowClosing(WindowEvent event) {
              dispose();
              System.exit(0);
              }
              });
        }
    }  // end VectorFrame class

