Class Text

  • All Implemented Interfaces:
    Animatable

    public class Text
    extends Drawable<Text>
    A Text element, used for drawing text on the canvas.
    
     Text text = new Text(100, 100, "Hello World");
     
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.awt.Font font
      The font of the text, you can change this if you want a different font (and have it installed)
      java.lang.String text
      The text to draw
    • Constructor Summary

      Constructors 
      Constructor Description
      Text​(int x, int y, java.lang.String text)
      Create a new Text element.
      Text​(int x, int y, java.lang.String text, java.awt.Color color)
      Create a new Text element.
      Text​(int x, int y, java.lang.String text, java.lang.String color)
      Create a new Text element with a certain color by name (see Hue for list of all valid names).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.Point center​(java.awt.Graphics g)
      Get the object's centerpoint
      protected void drawFilled​(java.awt.Graphics2D gc)
      the color is set to `color`
      protected void drawOutline​(java.awt.Graphics2D gc)
      the color is set to `outlineColor`, the stroke is set to `outlineStroke`
      int getFontSize()
      Get the current font size of the text.
      java.lang.String getText()
      Gets the current text of the element.
      protected Text getThis()  
      Text setFontSize​(double size)
      Set the current font size of the text.
      Text setText​(java.lang.String text)
      Sets the text of the element.
      • Methods inherited from class paintingcanvas.drawable.Drawable

        Modifier and Type Method Description
        AnimationBuilder animate()
        Start animating this object.
        java.awt.Point center​(java.awt.Graphics g)
        Get the object's centerpoint
        Drawable<?> drawable()
        Get the Drawable element from this Animatable.
        protected abstract void drawFilled​(java.awt.Graphics2D gc)
        the color is set to `color`
        protected abstract void drawOutline​(java.awt.Graphics2D gc)
        the color is set to `outlineColor`, the stroke is set to `outlineStroke`
        void erase()
        Erase this object from the canvas.
        java.awt.Color getColor()
        Get the current color of an element as a Color
        java.awt.Color getOutlineColor()
        Gets the outline color
        java.awt.Stroke getOutlineStroke()
        Gets the outline stroke
        java.awt.Point getPos()
        Get the position of the element
        double getRotation()
        Get an elements rotation
        protected abstract T getThis()  
        int getX()
        Get the X-position of the element
        int getY()
        Get the Y-position of the element.
        T hide()
        Hide the Object.
        T move​(int x, int y)
        Moves this drawable by the specified x and y.
        T moveHorizontal​(int x)
        Moves this drawable by the specified x and y.
        T moveVertical​(int y)
        Moves this drawable by the specified x and y.
        T removeOutline()
        Removes the outline from the shape
        void render​(java.awt.Graphics g)
        Actually render the object itself
        T rotate​(double rotation)
        Rotate this element by rotation°.
        T setColor​(int hex)
        Set the color of the object with a 8-bit RGB hex literal.
        T setColor​(int r, int g, int b)
        Set the color of the element with RGB.
        T setColor​(java.awt.Color color)
        Set the color of the object with a Color object.
        T setColor​(java.lang.String color)
        Set the color of the object with a certain color by name (see Hue for list of all valid names)
        T setFilled​(boolean filled)
        Set whether this object is filled or not
        T setOutline​(int thickness)
        Sets the parameters for the outline of the shape, with the color defaulting to black
        T setOutline​(int thickness, java.awt.Color color)
        Sets the parameters for the outline of the shape
        T setOutline​(java.awt.Color color)
        Sets the outline color of the shape
        T setPos​(int x, int y)
        Set the position of the element.
        T setRotation​(double rotation)
        Set an elements rotation to rotation°.
        T setX​(int x)
        Set the X-position of the object
        T setY​(int y)
        Set the Y-position of the element
        T show()
        Show the Object
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • font

        public java.awt.Font font
        The font of the text, you can change this if you want a different font (and have it installed)
      • text

        public java.lang.String text
        The text to draw
    • Constructor Detail

      • Text

        public Text​(int x,
                    int y,
                    java.lang.String text)

        Create a new Text element. The default font size is 30, and the default font is comic sans :)

        It probably won't work on replit however. Comic sans is not installed on the replit servers by default.

        
         Text text = new Text(100, 100, "Hello World")
         
        Parameters:
        x - The X-position of the text
        y - The Y-position of the text
        text - The text
      • Text

        public Text​(int x,
                    int y,
                    java.lang.String text,
                    java.awt.Color color)

        Create a new Text element. The default font size is 30, and the default font is comic sans :)

        It probably won't work on replit however. Comic sans is not installed on the replit servers by default.

        
         Text text = new Text(100, 100, "Hello World", new Color(255, 0, 0))
         
        Parameters:
        x - The X-position of the text
        y - The Y-position of the text
        text - The text
        color - the color of the text
      • Text

        public Text​(int x,
                    int y,
                    java.lang.String text,
                    java.lang.String color)

        Create a new Text element with a certain color by name (see Hue for list of all valid names). The default font size is 30, and the default font is comic sans :)

        It probably won't work on replit however. Comic sans is not installed on the replit servers by default.

        
         Text text = new Text(100, 100, "Hello World", "red")
         
        Parameters:
        x - The X-position of the text
        y - The Y-position of the text
        text - The text
        color - The name of the color of the text (case-insensitive)
    • Method Detail

      • drawFilled

        protected void drawFilled​(java.awt.Graphics2D gc)
        Description copied from class: Drawable
        the color is set to `color`
        Specified by:
        drawFilled in class Drawable<Text>
        Parameters:
        gc - The graphics context to draw the object with
      • drawOutline

        protected void drawOutline​(java.awt.Graphics2D gc)
        Description copied from class: Drawable
        the color is set to `outlineColor`, the stroke is set to `outlineStroke`
        Specified by:
        drawOutline in class Drawable<Text>
        Parameters:
        gc - The graphics context to draw the object with
      • center

        public java.awt.Point center​(java.awt.Graphics g)
        Description copied from class: Drawable
        Get the object's centerpoint
        
         import java.awt.Point;
        
         Point p = drawable.getStartpoint();
         int x = p.x;
         int y = p.y;
         
        Overrides:
        center in class Drawable<Text>
        Parameters:
        g - Graphics context
        Returns:
        The object's center-point
      • getFontSize

        public int getFontSize()
        Get the current font size of the text.
        
         Text text = new Text(100, 100, "Hello World");
         text.setFontSize(40); // Set font size to 40 points
         System.out.println(text.getFontSize()); // Prints 40
         
        Returns:
        The font size in points
        See Also:
        setFontSize(double)
      • setFontSize

        public Text setFontSize​(double size)
        Set the current font size of the text.
        
         Text text = new Text(100, 100, "Hello World");
         text.setFontSize(40); // Set font size to 40 points
         System.out.println(text.getFontSize()); // Prints 40
         
        Parameters:
        size - the new font size of the text
        Returns:
        The original object to allow method chaining
        See Also:
        getFontSize()
      • getText

        public java.lang.String getText()
        Gets the current text of the element.
        
         Text text = new Text(100, 100, "Hello World");
         System.out.println(text.getText()); // => Hello World
         
        Returns:
        The text as a String
        See Also:
        setText(String)
      • setText

        public Text setText​(java.lang.String text)
        Sets the text of the element.
        
         Text text = new Text(100, 100, "Hello World");
         text.setText("Go Go Mango");
         
        Parameters:
        text - The new text for the element as a String
        Returns:
        The original object to allow method chaining