/* * File: HexagonTest3.java * * Draw a regular hexagon * * Copyright: Northeast Parallel Architectures Center * */ import java.applet.Applet; import java.awt.Graphics; import java.awt.Polygon; import java.awt.Color; public class HexagonTest3 extends Applet { // create reference to a polygon: private Polygon p1, p2; public void init() { // instantiate a polygon object: p1 = new Polygon(); // add points to make a rectangle: p1.addPoint( 25, 25 ); p1.addPoint( 225, 25 ); p1.addPoint( 225, 199 ); p1.addPoint( 25, 199 ); // instantiate a polygon object: p2 = new Polygon(); // add points to make a regular hexagon: p2.addPoint( 75, 25 ); p2.addPoint( 175, 25 ); p2.addPoint( 225, 112 ); p2.addPoint( 175, 199 ); p2.addPoint( 75, 199 ); p2.addPoint( 25, 112 ); } public void paint( Graphics g ) { // draw a square: g.setColor( Color.yellow ); g.drawPolygon( p1 ); // draw a hexagon: g.setColor( Color.red ); g.drawPolygon( p2 ); } }