1 /* 2 * File: Hexagon.java 3 * 4 * Hexagon class 5 * 6 * Copyright: Northeast Parallel Architectures Center 7 * 8 */ 9 10 import java.awt.Point; 11 12 // A hexagon is a polygon with six sides: 13 public class Hexagon extends MovablePolygon { 14 15 // Hexagon constructor #1: 16 public Hexagon() { 17 // invoke the no-argument constructor of the superclass: 18 super(); 19 } 20 21 // Hexagon constructor #2: 22 public Hexagon( int x1, int y1, 23 int x2, int y2, 24 int x3, int y3, 25 int x4, int y4, 26 int x5, int y5, 27 int x6, int y6 ) { 28 29 // invoke the no-argument constructor of the superclass: 30 super(); 31 32 // the 'this' reference is optional: 33 this.addPoint( x1, y1 ); 34 this.addPoint( x2, y2 ); 35 this.addPoint( x3, y3 ); 36 this.addPoint( x4, y4 ); 37 this.addPoint( x5, y5 ); 38 this.addPoint( x6, y6 ); 39 40 } 41 42 // Hexagon constructor #3: 43 public Hexagon( Point p1, 44 Point p2, 45 Point p3, 46 Point p4, 47 Point p5, 48 Point p6 ) { 49 50 // invoke Hexagon constructor #2: 51 this( p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, 52 p4.x, p4.y, p5.x, p5.y, p6.x, p6.y ); 53 54 } 55 56 // Hexagon constructor #4 (a regular hexagon centered 57 // at point (x,y) of radius r ): 58 public Hexagon( int x, int y, int r ) { 59 // invoke the corresponding constructor of the superclass: 60 super( x, y, r, 6 ); 61 } 62 63 }