/* * File: Triangle.java * * Triangle class * * Copyright: Northeast Parallel Architectures Center * */ import java.awt.Point; // A triangle is a polygon with three sides: public class Triangle extends MovablePolygon { // Triangle constructor #1: public Triangle() { // invoke the no-argument constructor of the superclass: super(); } // Triangle constructor #2: public Triangle( int x1, int y1, int x2, int y2, int x3, int y3 ) { // invoke the no-argument constructor of the superclass: super(); // the 'this' reference is optional: this.addPoint( x1, y1 ); this.addPoint( x2, y2 ); this.addPoint( x3, y3 ); } // Triangle constructor #3: public Triangle( Point p1, Point p2, Point p3 ) { // invoke Triangle constructor #2: this( p1.x, p1.y, p2.x, p2.y, p3.x, p3.y ); } // Triangle constructor #4 (an equilateral triangle // centered at point (x,y) of radius r): public Triangle( int x, int y, int r ) { // invoke the corresponding constructor of the superclass: super( x, y, r, 3 ); } }