1  /*
  2   *  File:  TriangleTest2.java
  3   *
  4   *  Drawing triangles
  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  import java.awt.Color;
 14  
 15  public class TriangleTest2 extends Applet {
 16  
 17     // create references to three polygons:
 18     private Polygon p1, p2, p3;
 19     
 20     public void init() {
 21     
 22        // instantiate a polygon object:
 23        p1 = new Polygon();
 24  
 25        // add points to make a triangle:
 26        p1.addPoint( 50, 25 );
 27        p1.addPoint( 75, 100 );
 28        p1.addPoint( 25, 100 );
 29  
 30        // instantiate a polygon object:
 31        p2 = new Polygon();
 32  
 33        // add points to make another triangle:
 34        p2.addPoint( 125, 25 );
 35        p2.addPoint( 175, 100 );
 36        p2.addPoint( 125, 100 );
 37  
 38        // instantiate a polygon object:
 39        p3 = new Polygon();
 40  
 41        // add points to make a third triangle:
 42        p3.addPoint( 71, 125 );
 43        p3.addPoint( 129, 125 );
 44        p3.addPoint( 100, 175 );
 45  
 46     }
 47     
 48     public void paint( Graphics g ) {
 49  
 50        // draw a triangle:
 51        g.drawPolygon( p1 );
 52  
 53        // draw another triangle:
 54        g.fillPolygon( p2 );
 55  
 56        // draw a third triangle:
 57        g.setColor( Color.red );
 58        g.fillPolygon( p3 );
 59  
 60     }
 61     
 62  }