Package breadboards

Class GLine

  • All Implemented Interfaces:
    Drawable

    public class GLine
    extends GObject
    Subclass of GObject used for displaying line segments
    Author:
    paul oser
    • Constructor Detail

      • GLine

        public GLine()
        constructs a zero-length segment from (0,0) to itself
      • GLine

        public GLine​(double x0,
                     double y0,
                     double x1,
                     double y1)
        constructs a segment from (x0,y0) to (x1,y1)
        Parameters:
        x0 - x-coordinate of starting point
        y0 - y-coordinate of starting point
        x1 - x-coordinate of end point
        y1 - y-coordinate of end point
    • Method Detail

      • getBounds

        public GRectangle getBounds()
        returns the bounding rectangle of the GLine
        Specified by:
        getBounds in class GObject
        Returns:
        the bounding rectangle of the GLine
      • getEndPoint

        public GPoint getEndPoint()
        returns end point of the GLine
        Returns:
        end point of the GLine
      • getStartPoint

        public GPoint getStartPoint()
        returns start point of the GLine
        Returns:
        start point of the GLine
      • getColor

        public java.awt.Color getColor()
        returns color of GLine
        Returns:
        color of GLine
      • setStartPoint

        public void setStartPoint​(double startX,
                                  double startY)
        sets the start point for the GLine
        Parameters:
        startX - x-coordinate for starting point
        startY - y-coordinate for starting point
      • setEndPoint

        public void setEndPoint​(double endX,
                                double endY)
        sets the end point for the GLine
        Parameters:
        endX - x-coordinate for end point
        endY - y-coordinate for end point
      • setColor

        public void setColor​(java.awt.Color color)
        sets the color for the GLine to the specified color
        Parameters:
        color - the specified color for the GLine
      • scale

        public void scale​(double sx,
                          double sy)
        keeping the same starting point, this scales the horizontal component of the GLine's length by sx, and the vertical component by sy
        Parameters:
        sx - the horizontal scaling factor
        sy - the vertical scaling factor
      • scale

        public void scale​(double sf)
        keeping the same starting point, this scales the length of the GLine by sf
        Parameters:
        sf - the scaling factor
      • contains

        public boolean contains​(double px,
                                double py)
        returns true if (x,y) is sufficiently close (i.e., within LINE_TOLERANCE) to the segment
        Specified by:
        contains in class GObject
        Parameters:
        px - x-coordinate of the point in question
        py - y-coordinate of the point in question
        Returns:
        true if and only if (x,y) is within LINE_TOLERANCE of the segment
      • draw

        public void draw​(java.awt.Graphics g)
        draws the GLine (generally not called directly)