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