java.lang.Object Triangle
public class Triangle
Constructor Summary | |
---|---|
Triangle(double p1x,
double p1y,
double p2x,
double p2y,
double p3x,
double p3y,
objectdraw.DrawingCanvas canvas)
Constructor that takes six double parameters, i.e., x,y-coordinate for three points |
|
Triangle(objectdraw.Location p1,
objectdraw.Location p2,
objectdraw.Location p3,
objectdraw.DrawingCanvas canvas)
Constructor that takes three Location parameters |
|
Triangle(Triangle tri,
objectdraw.DrawingCanvas canvas)
Constructor that makes a copy of a triangle from an existing triangle |
Method Summary | |
---|---|
boolean |
contains(objectdraw.Location p)
Returns true if the Location p is strictly inside the bounding box of the triangle, otherwise return false Specifically, all of the following are satisfied: p.getX() is less than the triangle's largest x-coordinate p.getX() is greater than the triangle's smallest x-coordinate p.getY() is less than the triangle's largest y-coordinate p.getY() is greater than the triangle's smallest y-coordinate For extra credit, you can implement this method so that it returns true only if the Location p is inside of the actual triangle. |
java.awt.Color |
getColor()
Returns the current color of the triangle |
double |
getHeight()
Returns the height of the triangle's surrounding box, i.e., The maximum y-coordinate minus the minimum y-coordinate |
double |
getWidth()
Returns the width of the triangle's surrounding box, i.e., The maximum x-coordinate minus the minimum x-coordinate |
double |
getX()
Returns the x-coordinate of the top-left corner of the triangle Specifically, this returns the smallest x-coordinate among the triangles three points |
double |
getY()
Returns the y-coordinate of the top-left corner of the triangle Specifically, this returns the smallest y-coordinate among the triangles three points |
void |
move(double x,
double y)
Moves the triangle in the x and y direction by the amounts specified; Use positive numbers to move x right and negative numbers to move x left Use positive numbers to move y down and negative numbers to move y up |
void |
moveTo(double x,
double y)
Moves the triangle to the specified x,y destination |
void |
removeFromCanvas()
Removes the triangle from the canvase Removes each of the three lines from the canvas |
void |
setColor(java.awt.Color c)
Sets the color of the triangle to a new color |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Triangle(double p1x, double p1y, double p2x, double p2y, double p3x, double p3y, objectdraw.DrawingCanvas canvas)
p1x
- A point's x-coordinatep1y
- A points' y-coordinatep2x
- A point's x-coordinatep2y
- A points' y-coordinatep3x
- A point's x-coordinatep3y
- A points' y-coordinatecanvas
- The canvas used to draw the trianglepublic Triangle(objectdraw.Location p1, objectdraw.Location p2, objectdraw.Location p3, objectdraw.DrawingCanvas canvas)
p1
- A point of the trianglep2
- A point of the trianglep3
- A point of the trianglecanvas
- The canvas used to draw the trianglepublic Triangle(Triangle tri, objectdraw.DrawingCanvas canvas)
tri
- The triangle to copycanvas
- The canvas used to draw the triangleMethod Detail |
---|
public boolean contains(objectdraw.Location p)
public java.awt.Color getColor()
public double getHeight()
public double getWidth()
public double getX()
x-coordinate
- of the top-left cornerpublic double getY()
y-coordinate
- of the top-left cornerpublic void move(double x, double y)
x
- Amount to move in the x direction (left or right)y
- Amount to move in the y direction (up or down)public void moveTo(double x, double y)
x
- The x-coordinate of the destination locationy
- The y-coordinate of the destination locationpublic void removeFromCanvas()
public void setColor(java.awt.Color c)
The
- new color (type Color)