/* * File: HexagonTest.java * * Drawing a hexagon * * Copyright: Northeast Parallel Architectures Center * */ import java.applet.Applet; import java.awt.Graphics; import java.awt.Polygon; import java.awt.Color; public class HexagonTest 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 square: p1.addPoint( 25, 25 ); p1.addPoint( 225, 25 ); p1.addPoint( 225, 225 ); p1.addPoint( 25, 225 ); // instantiate a polygon object: p2 = new Polygon(); // add points to make a hexagon: p2.addPoint( 25, 25 ); p2.addPoint( 125, 25 ); p2.addPoint( 225, 125 ); p2.addPoint( 225, 225 ); p2.addPoint( 125, 225 ); p2.addPoint( 25, 125 ); } 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 ); } }