-
Notifications
You must be signed in to change notification settings - Fork 0
Line
CoolPotato31F edited this page Mar 19, 2025
·
1 revision
The Line class represents a line segment between two points. It implements the GraphicsObject interface and supports customizable width, outline color, and line styles (solid, dotted, dashed).
public Line(Point p1, Point p2)- p1: The starting point of the line.
- p2: The ending point of the line.
- Initializes a line between the given points.
Sets the outline color of the line.
- color: The new outline color.
Sets the first point of the line.
- point: The new first point.
Sets the second point of the line.
- point: The new second point.
Returns the width (thickness) of the line.
-
Returns:
int- The width of the line.
Sets the width (thickness) of the line.
- width: The new width of the line.
Sets the type of the line (solid, dotted, or dashed).
- type: The new line type.
- Throws an
IllegalArgumentExceptionif the type is invalid.
Calculates and returns the length of the line.
-
Returns:
double- The length of the line.
Draws the line on the provided graphical window.
-
canvas: The
GraphWinwhere the line will be drawn. - Throws
IllegalStateExceptionif the object is already drawn.
Removes the line from the graphical window.
Draws the line on a Graphics2D panel with the appropriate stroke style based on the lineType.
-
graphics: The
Graphics2Dobject used for rendering.