Class Triangle

java.lang.Object
  extended by DrawableShape
      extended by Triangle

public class Triangle
extends DrawableShape

An equilateral triangle that can be manipulated and drawn.

Version:
Jan 2013
Author:
Joel Ross, adapted from Michael Kolling and David J. Barnes

Constructor Summary
Triangle()
          Creates a new Triangle object with default location, radius, and color.
 
Method Summary
 void draw(java.awt.Graphics2D g2d)
           
 java.lang.String getColor()
          Get the triangle's current color
 double getRotation()
          Get the triangle's current rotation (in radians)
 int getSideLength()
          Get the triangle's current side length
 int getXPosition()
          Get the triangle's current x position
 int getYPosition()
          Get the triangle's current y position
 boolean isFilled()
          Get whether the triangle is filled
 void moveDown()
          Move the triangle a few pixels down.
 void moveHorizontal(int distance)
          Move the triangle horizontally by distance pixels.
 void moveLeft()
          Move the triangle a few pixels to the left.
 void moveRight()
          Move the triangle a few pixels to the right.
 void moveUp()
          Move the triangle a few pixels up.
 void moveVertical(int distance)
          Move the triangle vertically by distance pixels.
 void setColor(java.lang.String color)
          Set the triangle's new color
 void setFilled(boolean filled)
          Set whether the triangle is filled; can either be true or false
 void setRotation(double rotation)
          Set the triangle's current rotation (in radians).
 void setSideLength(int sideLength)
          Set the triangle's new side length
 void setXPosition(int x)
          Set the triangle's new x position
 void setYPosition(int y)
          Set the triangle's new x position
 
Methods inherited from class DrawableShape
getColorFromString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Triangle

public Triangle()
Creates a new Triangle object with default location, radius, and color.

Method Detail

draw

public void draw(java.awt.Graphics2D g2d)
Specified by:
draw in class DrawableShape

getColor

public java.lang.String getColor()
Get the triangle's current color

Returns:
The Triangle's current color (as a String). Can either be: "red", "green", "blue", "cyan", "magenta", "yellow", "pink", "gray", "black", "white"

getRotation

public double getRotation()
Get the triangle's current rotation (in radians)

Returns:
Triangle's current rotation (in radians)

getSideLength

public int getSideLength()
Get the triangle's current side length

Returns:
Triangle's current side length

getXPosition

public int getXPosition()
Get the triangle's current x position

Returns:
Triangle's current x position

getYPosition

public int getYPosition()
Get the triangle's current y position

Returns:
Triangle's current y position

isFilled

public boolean isFilled()
Get whether the triangle is filled

Returns:
Whether the triangle is filled or not

moveDown

public void moveDown()
Move the triangle a few pixels down.


moveHorizontal

public void moveHorizontal(int distance)
Move the triangle horizontally by distance pixels.

Parameters:
distance - The distance the triangle should move horizontally

moveLeft

public void moveLeft()
Move the triangle a few pixels to the left.


moveRight

public void moveRight()
Move the triangle a few pixels to the right.


moveUp

public void moveUp()
Move the triangle a few pixels up.


moveVertical

public void moveVertical(int distance)
Move the triangle vertically by distance pixels.

Parameters:
distance - The distance the triangle should move vertically

setColor

public void setColor(java.lang.String color)
Set the triangle's new color

Parameters:
color - The Triangle's new color. Can either be: "red", "green", "blue", "cyan", "magenta", "yellow", "pink", "gray", "black", "white"

setFilled

public void setFilled(boolean filled)
Set whether the triangle is filled; can either be true or false

Parameters:
filled - Whether the triangle should be filled; can either be true or false

setRotation

public void setRotation(double rotation)
Set the triangle's current rotation (in radians). Note that this number should have a decimal value.

Parameters:
radius - Triangle's new rotation (in radians). Note that this number should have a decimal value.

setSideLength

public void setSideLength(int sideLength)
Set the triangle's new side length

Parameters:
radius - Triangle's new side length

setXPosition

public void setXPosition(int x)
Set the triangle's new x position

Parameters:
x - Triangle's new x position

setYPosition

public void setYPosition(int y)
Set the triangle's new x position

Parameters:
y - Triangle's new y position