Package doodlepad

Class Line


public class Line extends Shape
A class that implements a graphical straight line shape.
  • Constructor Details

    • Line

      public Line(double x1, double y1, double x2, double y2)
      Line object constructor.
      Parameters:
      x1 - The x-coordinate of the Line object's first point.
      y1 - The y-coordinate of the Line object's first point.
      x2 - The x-coordinate of the Line object's second point.
      y2 - The y-coordinate of the Line object's second point.
    • Line

      public Line(double x1, double y1, double x2, double y2, Pad pad)
      Line object constructor.
      Parameters:
      x1 - The x-coordinate of the Line object's first point.
      y1 - The y-coordinate of the Line object's first point.
      x2 - The x-coordinate of the Line object's second point.
      y2 - The y-coordinate of the Line object's second point.
      pad - The Pad object to which this Line should be added.
    • Line

      public Line(double x1, double y1, double x2, double y2, Layer layer)
      Line object constructor.
      Parameters:
      x1 - The x-coordinate of the Line object's first point.
      y1 - The y-coordinate of the Line object's first point.
      x2 - The x-coordinate of the Line object's second point.
      y2 - The y-coordinate of the Line object's second point.
      layer - The Layer object to which the Line should be added, or null if not to add to a Layer.
    • Line

      public Line()
      Default constructor for the Line object. Creates a new 100x100 draggable shape and positions it randomly.
  • Method Details

    • setPoints

      public void setPoints(double x1, double y1, double x2, double y2)
      Set new endpoint locations for the Line object
      Parameters:
      x1 - The x-coordinate of the line's first point.
      y1 - The y-coordinate of the line's first point.
      x2 - The x-coordinate of the line's second point.
      y2 - The y-coordinate of the line's second point.
    • toString

      public String toString()
      Generate a representation of the Line object.
      Overrides:
      toString in class Shape
      Returns:
      String representation
    • draw

      public void draw(Graphics2D g)
      Draw the Line object
      Specified by:
      draw in class Shape
      Parameters:
      g - The Graphics2D object on which to draw the Line
    • getArea

      public Area getArea()
      Complete the area of the Line object
      Overrides:
      getArea in class Shape
      Returns:
      An Area object