/* **************************************************************************** * Kelli Wiseth * kelli@alameda-tech-lab.com * CIS 255AX * Program name: MyTriangle.java * Program Description: The subclass of MyLine that creates triangles. The * points from MyLine are inherited and used to create two of the three * lines in the triangle. The third point is a private member of the * MyTriangle class. * * Assignment #4 * 29 March 2005 **************************************************************************** */ import java.awt.*; public class MyTriangle extends MyLine { private Point point; //the default constructor (with no args that sets all coordinates to 0) public MyTriangle(){ super(); setPoint(0,0); } public MyTriangle(int x1, int y1, int x2, int y2, int x3, int y3){ super(x1, y1, x2, y2); setPoint(x3, y3); } public int getPointX(){ return point.getX(); } public int getPointY(){ return point.getY(); } public void setPoint(int x3, int y3){ point = new Point(x3, y3); } /******************************************************************** * The draw method overrides the draw() method in the MyLine class. We're * able to call the inherited methods of MyLine directly to draw the * lines that comprise the triangle. ******************************************************************** */ public void draw( Graphics g){ g.drawLine(getBeginPointX(), getBeginPointY(), getEndPointX(), getEndPointY()); g.drawLine(getEndPointX(), getEndPointY(), getPointX(), getPointY()); g.drawLine(getPointX(), getPointY(), getBeginPointX(), getBeginPointY()); } } // MyTriangle