1  /*
  2   *  File:  QuadrilateralTest.java
  3   *
  4   *  Drawing quadrilaterals
  5   *
  6   *  Copyright:  Northeast Parallel Architectures Center
  7   *  
  8   */
  9  
 10  import java.applet.Applet;
 11  import java.awt.Graphics;
 12  import java.awt.Polygon;
 13  
 14  public class QuadrilateralTest extends Applet {
 15  
 16     // create references to two polygons:
 17     private Polygon p1, p2;
 18     
 19     public void init() {
 20  
 21        // instantiate a Polygon object:
 22        p1 = new Polygon();
 23        
 24        // add points to make a rectangle (a kind of quadrilateral):
 25        p1.addPoint(  25,  25 );
 26        p1.addPoint( 125,  25 );
 27        p1.addPoint( 125,  75 );
 28        p1.addPoint(  25,  75 );
 29  
 30        // instantiate a Polygon object:
 31        p2 = new Polygon();
 32  
 33        // add points to make a parallelogram (another kind of quadrilateral):
 34        p2.addPoint( 165,  25 );
 35        p2.addPoint( 265,  25 );
 36        p2.addPoint( 250,  75 );
 37        p2.addPoint( 150,  75 );
 38  
 39  
 40  //       // Here's another way to do it:
 41  //
 42  //       // vertices of a rectangle (a kind of quadrilateral):
 43  //       int xValues1[] = {  25, 125, 125,  25 };
 44  //       int yValues1[] = {  25,  25,  75,  75 };
 45  // 
 46  //       // vertices of a parallelogram (another kind of quadrilateral):
 47  //       int xValues2[] = { 165, 265, 250, 150 };
 48  //       int yValues2[] = {  25,  25,  75,  75 };
 49  // 
 50  //       // instantiate the rectangle:
 51  //       p1 = new Polygon( xValues1, yValues1, 4 );
 52  //       
 53  //       // instantiate the parallelogram:
 54  //       p2 = new Polygon( xValues2, yValues2, 4 );
 55  
 56     }
 57     
 58     public void paint( Graphics g ) {
 59  
 60        // draw the rectangle:
 61        g.drawPolygon( p1 );
 62  
 63        // draw the parallelogram:
 64        g.fillPolygon( p2 );
 65  
 66     }
 67     
 68  }