1  /*
  2   *  File:  HexagonTest.java
  3   *
  4   *  Drawing a hexagon
  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 HexagonTest extends Applet {
 16  
 17     // create reference to a polygon:
 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( 225,  25 );
 28        p1.addPoint( 225, 225 );
 29        p1.addPoint(  25, 225 );
 30  
 31        // instantiate a polygon object:
 32        p2 = new Polygon();
 33  
 34        // add points to make a hexagon:
 35        p2.addPoint(  25,  25 );
 36        p2.addPoint( 125,  25 );
 37        p2.addPoint( 225, 125 );
 38        p2.addPoint( 225, 225 );
 39        p2.addPoint( 125, 225 );
 40        p2.addPoint(  25, 125 );
 41  
 42     }
 43     
 44     public void paint( Graphics g ) {
 45  
 46        // draw a square:
 47        g.setColor( Color.yellow );
 48        g.drawPolygon( p1 );
 49  
 50        // draw a hexagon:
 51        g.setColor( Color.red );
 52        g.drawPolygon( p2 );
 53  
 54     }
 55     
 56  }