wheels.users
Class Line

java.lang.Object
  extended bywheels.etc.AbstractGraphic
      extended bywheels.users.Shape
          extended bywheels.users.Line
All Implemented Interfaces:
Colorable, CustomGraphic, Rotatable

public class Line
extends Shape

Class that models a 2D line. Has methods allowing you to adjust the line's points, thickness, color, etc.

Author:
Sanders & van Dam. Object-Oriented Programming in Java.

Field Summary
static int DEFAULT_LENGTH
           
 
Fields inherited from class wheels.users.Shape
_dp, _shape, DEFAULT_COLOR
 
Constructor Summary
Line()
          Creates a Line with default endpoints in the wheels.users.Frame's DrawingPanel.
Line(DrawingPanel dp)
          Creates a Line with endpoints (0, 0) and (0, 0) in the specified DrawingPanel.
Line(DrawingPanel dp, int x1, int y1, int x2, int y2)
          Creates a Line with the specified endpoint coordinates in the specified DrawingPanel.
Line(DrawingPanel dp, Point p1, Point p2)
          Creates a Line with the specified endpoints in the specified DrawingPanel.
Line(int x1, int y1, int x2, int y2)
          Creates a Line with the specified coordinates in the wheels.users.Frame's DrawingPanel.
Line(Point p1, Point p2)
          Creates a Line with the specified endpoints in the wheels.users.Frame's DrawingPanel.
 
Method Summary
 void actualPaint(Graphics2D g)
          Subclasses must define this to do the actual painting of the shape.
 Rectangle getBounds()
          Returns the bounding rectangle of the line.
 Point getP1()
          Returns the first endpoint.
 Point getP2()
          Returns the second endpoint.
 int getThickness()
          Returns the thickness of the stroke.
 int getX1()
          Return the x coordinate of the first endpoint.
 int getX2()
          Return the x coordinate of the second endpoint.
 int getY1()
          Returns the y coordinate of the first endpoint.
 int getY2()
          Returns the y coordinate of the second endpoint.
 void setP1(int x, int y)
          Sets the coordinates of the first endpoint.
 void setP1(Point p1)
          Set the first endpoint.
 void setP2(int x, int y)
          Sets the coordinates of the second endpoint.
 void setP2(Point p2)
          Set the second endpoint.
 void setPoints(int x1, int y1, int x2, int y2)
          Sets the endpoints of the Line to the specified coordinates
 void setPoints(Point p1, Point p2)
          Sets the endpoints of the Line to the specified values.
 void setThickness(int thickness)
          Sets the thickness of the stroke used to paint the line.
 
Methods inherited from class wheels.users.Shape
contains, getColor, getRotation, hide, paint, setColor, setRotation, show
 
Methods inherited from class wheels.etc.AbstractGraphic
mouseClicked, mouseDragged, mousePressed, mouseReleased
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LENGTH

public static final int DEFAULT_LENGTH
See Also:
Constant Field Values
Constructor Detail

Line

public Line()
Creates a Line with default endpoints in the wheels.users.Frame's DrawingPanel.


Line

public Line(int x1,
            int y1,
            int x2,
            int y2)
Creates a Line with the specified coordinates in the wheels.users.Frame's DrawingPanel.

Parameters:
x1 - the x value of the first endpoint
y1 - the y value of the first endpoint
x2 - the x value of the second endpoint
y2 - the y value of the second endpoint

Line

public Line(Point p1,
            Point p2)
Creates a Line with the specified endpoints in the wheels.users.Frame's DrawingPanel.

Parameters:
p1 - the first endpoint
p2 - the second endpoint

Line

public Line(DrawingPanel dp)
Creates a Line with endpoints (0, 0) and (0, 0) in the specified DrawingPanel.


Line

public Line(DrawingPanel dp,
            int x1,
            int y1,
            int x2,
            int y2)
Creates a Line with the specified endpoint coordinates in the specified DrawingPanel.

Parameters:
dp - the DrawingPanel in which the line will be drawn
x1 - the x value of the first endpoint
y1 - the y value of the first endpoint
x2 - the x value of the second endpoint
y2 - the y value of the second endpoint

Line

public Line(DrawingPanel dp,
            Point p1,
            Point p2)
Creates a Line with the specified endpoints in the specified DrawingPanel.

Parameters:
dp - the DrawingPanel in which the line will be drawn
p1 - the first endpoint
p2 - the second endpoint
Method Detail

setPoints

public void setPoints(int x1,
                      int y1,
                      int x2,
                      int y2)
Sets the endpoints of the Line to the specified coordinates


setPoints

public void setPoints(Point p1,
                      Point p2)
Sets the endpoints of the Line to the specified values.


setP1

public void setP1(int x,
                  int y)
Sets the coordinates of the first endpoint.


setP1

public void setP1(Point p1)
Set the first endpoint.


setP2

public void setP2(int x,
                  int y)
Sets the coordinates of the second endpoint.


setP2

public void setP2(Point p2)
Set the second endpoint.


getP1

public Point getP1()
Returns the first endpoint.


getX1

public int getX1()
Return the x coordinate of the first endpoint.


getY1

public int getY1()
Returns the y coordinate of the first endpoint.


getP2

public Point getP2()
Returns the second endpoint.


getX2

public int getX2()
Return the x coordinate of the second endpoint.


getY2

public int getY2()
Returns the y coordinate of the second endpoint.


setThickness

public void setThickness(int thickness)
Sets the thickness of the stroke used to paint the line.


getThickness

public int getThickness()
Returns the thickness of the stroke.


getBounds

public Rectangle getBounds()
Returns the bounding rectangle of the line.

Overrides:
getBounds in class Shape

actualPaint

public void actualPaint(Graphics2D g)
Description copied from class: Shape
Subclasses must define this to do the actual painting of the shape. All calls to paint(java.awt.Graphics2D) will forward to this method.

Specified by:
actualPaint in class Shape
Parameters:
g - the instance of java.awt.Graphics2D that should be used to paint the shape