Class Text

    • 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 hue name or hex code
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.Point center​(java.awt.Graphics2D g)
      Get the object's centerpoint
      Anchor getAnchor()
      Get the current anchor of the element.
      java.awt.FontMetrics getFontMetrics()
      If you need more information about the text, such as ascent, descent, leading, etc.
      int getFontSize()
      Get the current font size of the text.
      int getHeight()
      Note that the computed height of the text only gets updated when the text is drawn.
      java.lang.String getText()
      Gets the current text of the element.
      Text getThis()  
      int getWidth()
      Note that the computed width of the text only gets updated when the text is drawn.
      void internalSetAnchor​(Anchor anchor)  
      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 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface paintingcanvas.animation.Animatable

        Modifier and Type Method Description
        default AnimationBuilder colorTo​(int hex, double duration)
        Change the color of this to the specified color over duration seconds.
        default AnimationBuilder colorTo​(int r, int g, int b, double duration)
        Change the color of this to the specified color over duration seconds.
        default AnimationBuilder colorTo​(int r, int g, int b, int a, double duration)
        Change the color of this to the specified color over duration seconds.
        default AnimationBuilder colorTo​(java.awt.Color color, double duration)
        Change the color of this to the specified color over duration seconds.
        default AnimationBuilder colorTo​(java.lang.String name, double duration)
        Change the color of this to the specified color over duration seconds.
        default AnimationBuilder colorTo​(Hue hue, double duration)
        Change the color of this to the specified color over duration seconds.
        Drawable<?> drawable()
        Get the Drawable element from this Animatable.
        default AnimationBuilder fadeIn​(double duration)
        Fade this in over duration seconds.
        default AnimationBuilder fadeOut​(double duration)
        Fade this out over duration seconds.
        default AnimationBuilder moveBy​(int x, int y, double duration)
        Move this by the specified x and y over duration seconds.
        default AnimationBuilder moveHorizontalBy​(int x, double duration)
        Move this by the specified x horizontally over duration seconds.
        default AnimationBuilder moveTo​(int x, int y, double duration)
        Move this to the specified x and y over duration seconds
        default AnimationBuilder moveVerticalBy​(int y, double duration)
        Move this by the specified y vertically over duration seconds.
        default AnimationBuilder rotateBy​(int angle, double duration)
        Rotate this by angle degrees over duration seconds.
        default AnimationBuilder rotateTo​(int angle, double duration)
        Rotate this to the specified angle degrees over duration seconds.
      • Methods inherited from interface paintingcanvas.drawable.Colorable

        Modifier and Type Method Description
        java.awt.Color getColor()
        Get the current color of an element as a Color
        void internalSetColor​(java.awt.Color color)  
        default T setColor​(int hex)
        Set the color of this to the specified color.
        default T setColor​(int r, int g, int b)
        Set the color of this to the specified color.
        default T setColor​(int r, int g, int b, int a)
        Set the color of this to the specified color See Wikipedia for how this works.
        default T setColor​(java.awt.Color color)
        Set the color of the object with a Color object.
        default T setColor​(java.lang.String name)
        Set the color of the object with a hue name or hex code.
        default T setColor​(Hue hue)
        Set the color of the object with a Hue object.
      • Methods inherited from interface paintingcanvas.drawable.Drawable

        Modifier and Type Method Description
        default AnimationBuilder animate()
        Start animating this object.
        default T bringToFront()
        Brings the object in front of all other objects.
        java.awt.Point center​(java.awt.Graphics2D g)
        Get the object's centerpoint
        default Drawable<?> drawable()
        Get the Drawable element from this Animatable.
        default void erase()
        Erase this object from the canvas.
        int getLayer()
        Gets the current layer of the object.
        T getThis()  
        T hide()
        Hide the Object.
        void internalSetLayer​(int layer)  
        void render​(java.awt.Graphics2D g)
        Actually render the object itself
        default T sendToBack()
        Puts the object behind all other objects.
        default T setLayer​(int layer)
        Puts the object on a specific layer.
        T show()
        Show the Object
      • Methods inherited from interface paintingcanvas.drawable.Positionable

        Modifier and Type Method Description
        java.awt.Point getPos()
        Get the position of the element
        double getRotation()
        Get an elements rotation
        default int getX()
        Get the X-position of the element
        default int getY()
        Get the Y-position of the element.
        double internalGetRotation()  
        void internalSetPos​(int x, int y)  
        void internalSetRotation​(double rotation)  
        default T move​(int x, int y)
        Moves this drawable by the specified x and y.
        default T moveHorizontal​(int x)
        Moves this drawable by the specified x and y.
        default T moveVertical​(int y)
        Moves this drawable by the specified x and y.
        default T rotate​(double rotation)
        Rotate this element by rotation degrees.
        default T setPos​(int x, int y)
        Set the position of the element.
        default T setRotation​(double rotation)
        Set an elements rotation to rotation degrees.
        default T setX​(int x)
        Set the X-position of the object
        default T setY​(int y)
        Set the Y-position of the element
    • 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
    • Method Detail

      • center

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

        public int getWidth()

        Note that the computed width of the text only gets updated when the text is drawn. (i.e. it does not get updated immediately)

        Returns:
        The width of the text in pixels.
      • getHeight

        public int getHeight()

        Note that the computed height of the text only gets updated when the text is drawn. (i.e. it does not get updated immediately)

        Returns:
        The height of the text in pixels.
      • getFontMetrics

        public java.awt.FontMetrics getFontMetrics()
        If you need more information about the text, such as ascent, descent, leading, etc. the information can be retrieved from the FontMetrics object.

        Again, note that the metrics are only updated when the text is drawn. (i.e. it does not get updated immediately)

        Returns:
        The FontMetrics object containing information about the text
      • 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
      • getAnchor

        public Anchor getAnchor()
        Description copied from interface: Anchorable
        Get the current anchor of the element.
        Specified by:
        getAnchor in interface Anchorable<Text>
        Returns:
        the Anchor of the element; how its positioned relative to its center