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