Class Line

java.lang.Object
  extended by Line
All Implemented Interfaces:
Shape

public class Line
extends Object
implements Shape


Constructor Summary
Line(double x1, double y1, double x2, double y2)
          Constructs a line with a given starting and ending location.
 
Method Summary
 void draw()
          Shows this line on the canvas.
 int getHeight()
          Gets the height of the bounding box.
 int getWidth()
          Gets the width of the bounding box.
 int getX()
          Gets the leftmost x-position of the line.
 int getY()
          Gets the topmost y-position of the line.
 void grow(double dw, double dh)
          Resizes this line both horizontally and vertically.
 void paintShape(Graphics2D g2)
          Paints the shape
 void setColor(Color newColor)
          Sets the color for drawing this line.
 String toString()
           
 void translate(double dx, double dy)
          Moves this line by a given amount.
 
Methods inherited from class
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Line

public Line(double x1,
            double y1,
            double x2,
            double y2)
Constructs a line with a given starting and ending location.

Parameters:
x1 - the x-coordinate of the starting point
y1 - the y-coordinate of the starting point
x2 - the x-coordinate of the ending point
y2 - the y-coordinate of the ending point
Method Detail

draw

public void draw()
Shows this line on the canvas.


getHeight

public int getHeight()
Gets the height of the bounding box.

Specified by:
getHeight in interface Shape
Returns:
the height

getWidth

public int getWidth()
Gets the width of the bounding box.

Specified by:
getWidth in interface Shape
Returns:
the width

getX

public int getX()
Gets the leftmost x-position of the line.

Specified by:
getX in interface Shape
Returns:
the leftmost x-position

getY

public int getY()
Gets the topmost y-position of the line.

Specified by:
getY in interface Shape
Returns:
the topmost y-position

grow

public void grow(double dw,
                 double dh)
Resizes this line both horizontally and vertically.

Parameters:
dw - the amount by which to resize the width on each side
dw - the amount by which to resize the height on each side

paintShape

public void paintShape(Graphics2D g2)
Description copied from interface: Shape
Paints the shape

Specified by:
paintShape in interface Shape
Parameters:
g2 - the graphics object

setColor

public void setColor(Color newColor)
Sets the color for drawing this line.

Parameters:
newColor - the new color

toString

public String toString()
Overrides:
toString in class Object

translate

public void translate(double dx,
                      double dy)
Moves this line by a given amount.

Parameters:
dx - the amount by which to move in x-direction
dy - the amount by which to move in y-direction