1 /* 2 * File: HexagonTest3.java 3 * 4 * Draw a regular hexagon 5 * 6 * Copyright: Northeast Parallel Architectures Center 7 * 8 */ 9 10 import java.applet.Applet; 11 import java.awt.Graphics; 12 import java.awt.Polygon; 13 import java.awt.Color; 14 15 public class HexagonTest3 extends Applet { 16 17 // create reference to a polygon: 18 private Polygon p1, p2; 19 20 public void init() { 21 22 // instantiate a polygon object: 23 p1 = new Polygon(); 24 25 // add points to make a rectangle: 26 p1.addPoint( 25, 25 ); 27 p1.addPoint( 225, 25 ); 28 p1.addPoint( 225, 199 ); 29 p1.addPoint( 25, 199 ); 30 31 // instantiate a polygon object: 32 p2 = new Polygon(); 33 34 // add points to make a regular hexagon: 35 p2.addPoint( 75, 25 ); 36 p2.addPoint( 175, 25 ); 37 p2.addPoint( 225, 112 ); 38 p2.addPoint( 175, 199 ); 39 p2.addPoint( 75, 199 ); 40 p2.addPoint( 25, 112 ); 41 42 } 43 44 public void paint( Graphics g ) { 45 46 // draw a square: 47 g.setColor( Color.yellow ); 48 g.drawPolygon( p1 ); 49 50 // draw a hexagon: 51 g.setColor( Color.red ); 52 g.drawPolygon( p2 ); 53 54 } 55 56 }