1  /*
  2   *  File:  HexagonTest2.java
  3   *
  4   *  Draw a triangle inside a regular hexagon (an exercise)
  5   *
  6   *  Copyright:  Northeast Parallel Architectures Center
  7   *  
  8   */
  9  
 10  import java.applet.Applet;
 11  import java.awt.Point;
 12  import java.awt.Graphics;
 13  import java.awt.Color;
 14  
 15  public class HexagonTest2 extends Applet {
 16  
 17     // create a reference to a hexagon:
 18     private Hexagon hexagon;
 19     
 20     // create a reference to a triangle:
 21     private MyTriangle triangle;
 22  
 23     // create references to six points:
 24     private Point p1, p2, p3, p4, p5, p6;
 25     
 26     public void init() {
 27     
 28        // instantiate six points (the vertices of a regular hexagon):
 29        p1 = new Point(  75,  25 );
 30        p2 = new Point( 175,  25 );
 31        p3 = new Point( 225, 112 );
 32        p4 = new Point( 175, 199 );
 33        p5 = new Point(  75, 199 );
 34        p6 = new Point(  25, 112 );
 35  
 36        // instantiate a regular hexagon:
 37        hexagon = new Hexagon( p1, p2, p3, p4, p5, p6 );
 38        
 39        // instantiate a triangle inside the hexagon:
 40        triangle = new MyTriangle( p1, p3, p5 );
 41        
 42     }
 43     
 44     public void paint( Graphics g ) {
 45  
 46        // fill the hexagon:
 47        g.setColor( Color.red );
 48        hexagon.fill( g );
 49  
 50        // draw the triangle:
 51        g.setColor( Color.yellow );
 52        triangle.draw( g );
 53  
 54     }
 55     
 56  }