/* * File: HexagonTest2.java * * Draw a triangle inside a regular hexagon (an exercise) * * Copyright: Northeast Parallel Architectures Center * */ import java.applet.Applet; import java.awt.Point; import java.awt.Graphics; import java.awt.Color; public class HexagonTest2 extends Applet { // create a reference to a hexagon: private Hexagon hexagon; // create a reference to a triangle: private MyTriangle triangle; // create references to six points: private Point p1, p2, p3, p4, p5, p6; public void init() { // instantiate six points (the vertices of a regular hexagon): p1 = new Point( 75, 25 ); p2 = new Point( 175, 25 ); p3 = new Point( 225, 112 ); p4 = new Point( 175, 199 ); p5 = new Point( 75, 199 ); p6 = new Point( 25, 112 ); // instantiate a regular hexagon: hexagon = new Hexagon( p1, p2, p3, p4, p5, p6 ); // instantiate a triangle inside the hexagon: triangle = new MyTriangle( p1, p3, p5 ); } public void paint( Graphics g ) { // fill the hexagon: g.setColor( Color.red ); hexagon.fill( g ); // draw the triangle: g.setColor( Color.yellow ); triangle.draw( g ); } }