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

Text Class

Overview

The Text class represents a graphical text object that can be drawn on a graphical window. It supports font customization, alignment, background fill, and text outlines.

Attributes

  • private String content
    The string content of the text object.

  • private Point position
    The top-left position of the text in the graphical window.

  • private Font font
    The font style, size, and type of the text (default: Arial, plain, size 25).

  • private Color textFillColor
    The color of the text content (default: black).

  • private Color rectangleFillColor
    The background color of the bounding rectangle (default: none).

  • private Color borderColor
    The color of the rectangle's border (default: black).

  • private Color textOutlineColor
    The outline color of the text (default: black).

  • private int borderWidth
    The width of the rectangle's border (default: 1).

  • private int textOutlineWidth
    The width of the text outline (default: 0).

  • private GraphWin canvas
    The graphical window where the text is drawn.

  • private String alignment
    The alignment of the text: "left", "center", or "right" (default: "left").

Constructors

Text(String content, Point position)

Constructs a Text object with the specified content and position.

Parameters:

  • content - The text string to display.
  • position - The top-left position of the text.

Methods

void setFont(Font font)

Sets the font of the text.

Parameters:

  • font - The Font object specifying the font style.

void setFont(String fontName, int style, int size)

Sets the font using a font name, style, and size.

Parameters:

  • fontName - The name of the font.
  • style - The font style (e.g., Font.PLAIN, Font.BOLD).
  • size - The font size.

void setFill(Color color)

Sets the fill color of the text.

Parameters:

  • color - The color of the text.

void setBackground(Color color)

Sets the background color of the text's bounding rectangle.

Parameters:

  • color - The background color.

void setBorder(Color color)

Sets the border color of the bounding rectangle.

Parameters:

  • color - The color of the rectangle's border.

void setBorderWidth(int width)

Sets the border width of the bounding rectangle.

Parameters:

  • width - The width of the rectangle border.

void setOutline(Color color)

Sets the outline color of the text.

Parameters:

  • color - The color of the text outline.

void setOutlineWidth(int width)

Sets the width of the text outline.

Parameters:

  • width - The width of the text outline.

void setAlignment(String alignment)

Sets the alignment of the text.

Parameters:

  • alignment - The text alignment, must be "left", "center", or "right".

void draw(GraphWin canvas)

Draws the text on the given GraphWin canvas.

Parameters:

  • canvas - The GraphWin instance to draw the text on.

void undraw()

Removes the text from the graphical window.

void drawPanel(Graphics2D graphics)

Renders the text onto a Graphics2D panel, including background, border, and outline.

Parameters:

  • graphics - The Graphics2D object used for rendering.

See Also

Table of Contents

Home

Shapes
Advanced Shapes
Components
Animations
Instructions

Clone this wiki locally