/* * File: QuadrilateralTest2.java * * Drawing quadrilaterals * * Copyright: Northeast Parallel Architectures Center * */ import java.applet.Applet; import java.awt.Graphics; import java.awt.Polygon; public class QuadrilateralTest2 extends Applet { // create references to four polygons: private Polygon p1, p2, p3, p4; 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 ); // instantiate a Polygon object: p3 = new Polygon(); // add points to make a square (a kind of rectangle): p3.addPoint( 50, 100 ); p3.addPoint( 100, 100 ); p3.addPoint( 100, 150 ); p3.addPoint( 50, 150 ); // instantiate a Polygon object: p4 = new Polygon(); // add points to make a rhombus (a kind of parallelogram): p4.addPoint( 195, 110 ); p4.addPoint( 245, 110 ); p4.addPoint( 215, 150 ); p4.addPoint( 165, 150 ); // // 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 }; // // // vertices of a square (a kind of rectangle): // int xValues3[] = { 50, 100, 100, 50 }; // int yValues3[] = { 100, 100, 150, 150 }; // // // vertices of a rhombus (a kind of parallelogram): // int xValues4[] = { 195, 245, 215, 165 }; // int yValues4[] = { 110, 110, 150, 150 }; // // // instantiate the rectangle: // p1 = new Polygon( xValues1, yValues1, 4 ); // // instantiate the parallelogram: // p2 = new Polygon( xValues2, yValues2, 4 ); // // instantiate the square: // p3 = new Polygon( xValues3, yValues3, 4 ); // // instantiate the rhombus: // p4 = new Polygon( xValues4, yValues4, 4 ); } public void paint( Graphics g ) { // draw two quadrilaterals: g.drawPolygon( p1 ); g.drawPolygon( p3 ); // draw two filled quadrilaterals: g.fillPolygon( p2 ); g.fillPolygon( p4 ); } }