1  /*
  2   *  File:  OctagonTest2.java
  3   *
  4   *  Drawing a regular octagon
  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 OctagonTest2 extends Applet {
 16  
 17     // create references to two polygons:
 18     private Polygon p1, p2;
 19     
 20     public void init() {
 21     
 22        // instantiate a polygon object:
 23        p1 = new Polygon();
 24  
 25        // add points to make a square:
 26        p1.addPoint(  25,  25 );
 27        p1.addPoint( 175,  25 );
 28        p1.addPoint( 175, 175 );
 29        p1.addPoint(  25, 175 );
 30  
 31        // instantiate a polygon object:
 32        p2 = new Polygon();
 33  
 34        // add points to make a regular octagon:
 35        p2.addPoint(  69,  25 );
 36        p2.addPoint( 131,  25 );
 37        p2.addPoint( 175,  69 );
 38        p2.addPoint( 175, 131 );
 39        p2.addPoint( 131, 175 );
 40        p2.addPoint(  69, 175 );
 41        p2.addPoint(  25, 131 );
 42        p2.addPoint(  25,  69 );
 43  
 44     }
 45     
 46     public void paint( Graphics g ) {
 47  
 48        // draw a square:
 49        g.setColor( Color.yellow );
 50        g.drawPolygon( p1 );
 51  
 52        // draw a octagon:
 53        g.setColor( Color.red );
 54        g.drawPolygon( p2 );
 55  
 56     }
 57     
 58  }