/* * File: MyTriangle.java * * Triangle class * * Copyright: Northeast Parallel Architectures Center * */ import java.awt.Point; // A triangle is a polygon with three sides: class MyTriangle extends MyPolygon { // Triangle constructor #1: public MyTriangle() { // invoke the constructor of the superclass Polygon: super(); } // Triangle constructor #2: public MyTriangle( int x1, int y1, int x2, int y2, int x3, int y3 ) { // invoke the constructor of the superclass Polygon: super(); // the 'this' reference is optional: this.addPoint( x1, y1 ); this.addPoint( x2, y2 ); this.addPoint( x3, y3 ); } // Triangle constructor #3: public MyTriangle( Point p1, Point p2, Point p3 ) { // invoke Triangle constructor #2: this( p1.x, p1.y, p2.x, p2.y, p3.x, p3.y ); } }