/* * File: QuadrilateralTest.java * * Drawing quadrilaterals * * Copyright: Northeast Parallel Architectures Center * */ import java.applet.Applet; import java.awt.Graphics; import java.awt.Polygon; public class QuadrilateralTest extends Applet { // create references to two polygons: private Polygon p1, p2; public void init() { // instantiate a Polygon object: p1 = new Polygon(); // add points to make a rectangle (a kind of quadrilateral): p1.addPoint( 25, 25 ); p1.addPoint( 125, 25 ); p1.addPoint( 125, 75 ); p1.addPoint( 25, 75 ); // instantiate a Polygon object: p2 = new Polygon(); // add points to make a parallelogram (another kind of quadrilateral): p2.addPoint( 165, 25 ); p2.addPoint( 265, 25 ); p2.addPoint( 250, 75 ); p2.addPoint( 150, 75 ); // // Here's another way to do it: // // // vertices of a rectangle (a kind of quadrilateral): // int xValues1[] = { 25, 125, 125, 25 }; // int yValues1[] = { 25, 25, 75, 75 }; // // // vertices of a parallelogram (another kind of quadrilateral): // int xValues2[] = { 165, 265, 250, 150 }; // int yValues2[] = { 25, 25, 75, 75 }; // // // instantiate the rectangle: // p1 = new Polygon( xValues1, yValues1, 4 ); // // // instantiate the parallelogram: // p2 = new Polygon( xValues2, yValues2, 4 ); } public void paint( Graphics g ) { // draw the rectangle: g.drawPolygon( p1 ); // draw the parallelogram: g.fillPolygon( p2 ); } }