-
Notifications
You must be signed in to change notification settings - Fork 0
Text
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.
-
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").
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.
Sets the font of the text.
Parameters:
-
font- TheFontobject specifying the font style.
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.
Sets the fill color of the text.
Parameters:
-
color- The color of the text.
Sets the background color of the text's bounding rectangle.
Parameters:
-
color- The background color.
Sets the border color of the bounding rectangle.
Parameters:
-
color- The color of the rectangle's border.
Sets the border width of the bounding rectangle.
Parameters:
-
width- The width of the rectangle border.
Sets the outline color of the text.
Parameters:
-
color- The color of the text outline.
Sets the width of the text outline.
Parameters:
-
width- The width of the text outline.
Sets the alignment of the text.
Parameters:
-
alignment- The text alignment, must be"left","center", or"right".
Draws the text on the given GraphWin canvas.
Parameters:
-
canvas- TheGraphWininstance to draw the text on.
Removes the text from the graphical window.
Renders the text onto a Graphics2D panel, including background, border, and outline.
Parameters:
-
graphics- TheGraphics2Dobject used for rendering.