Skip to content
CoolPotato31F edited this page Mar 19, 2025 · 1 revision

Line Class

Overview

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).

Constructor

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.

Methods

setOutline(Color color)

Sets the outline color of the line.

  • color: The new outline color.

setP1(Point point)

Sets the first point of the line.

  • point: The new first point.

setP2(Point point)

Sets the second point of the line.

  • point: The new second point.

getWidth()

Returns the width (thickness) of the line.

  • Returns: int - The width of the line.

setWidth(int width)

Sets the width (thickness) of the line.

  • width: The new width of the line.

setType(String type)

Sets the type of the line (solid, dotted, or dashed).

  • type: The new line type.
  • Throws an IllegalArgumentException if the type is invalid.

getLength()

Calculates and returns the length of the line.

  • Returns: double - The length of the line.

draw(GraphWin canvas)

Draws the line on the provided graphical window.

  • canvas: The GraphWin where the line will be drawn.
  • Throws IllegalStateException if the object is already drawn.

undraw()

Removes the line from the graphical window.

drawPanel(Graphics2D graphics)

Draws the line on a Graphics2D panel with the appropriate stroke style based on the lineType.

  • graphics: The Graphics2D object used for rendering.

See Also

Table of Contents

Home

Shapes
Advanced Shapes
Components
Animations
Instructions

Clone this wiki locally