Class Rectangle

  • All Implemented Interfaces:
    Animatable

    public class Rectangle
    extends Drawable<Rectangle>
    A Rectangle element.
    
     // Create a new Rectangle at (100, 100) with a width of 20 and a height of 30
     Rectangle rectangle = new Rectangle(100, 100, 20, 30);
     
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int height
      The height of the rectangle.
      int width
      The width of the rectangle.
    • Constructor Summary

      Constructors 
      Constructor Description
      Rectangle​(int centerX, int centerY, int width, int height)
      Create a new Rectangle element.
      Rectangle​(int centerX, int centerY, int width, int height, java.awt.Color color)
      Create a new Rectangle element.
      Rectangle​(int centerX, int centerY, int width, int height, java.lang.String color)
      Create a new Rectangle 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
      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 getHeight()
      Gets the height of the rectangle.
      protected Rectangle getThis()  
      int getWidth()
      Gets the width of the rectangle.
      Rectangle setHeight​(int h)
      Sets the height of the rectangle.
      Rectangle setWidth​(int w)
      Sets the width of the rectangle.
      • 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

      • width

        public int width
        The width of the rectangle.
      • height

        public int height
        The height of the rectangle.
    • Constructor Detail

      • Rectangle

        public Rectangle​(int centerX,
                         int centerY,
                         int width,
                         int height)
        Create a new Rectangle element.
        
         // Create a new Rectangle centered at (100, 100) with a width of 20 and a height of 30
         Rectangle rectangle = new Rectangle(100, 100, 20, 30);
         
        Parameters:
        centerX - The X-position of the rectangle
        centerY - The Y-position of the rectangle
        width - The width of the rectangle
        height - The height of the rectangle
      • Rectangle

        public Rectangle​(int centerX,
                         int centerY,
                         int width,
                         int height,
                         java.awt.Color color)
        Create a new Rectangle element.
        
         // Create a new red Rectangle centered at (100, 100) with a width of 20 and a height of 30
         Rectangle rectangle = new Rectangle(100, 100, 20, 30, new Color(255, 0, 0));
         
        Parameters:
        centerX - The X-position of the rectangle
        centerY - The Y-position of the rectangle
        width - The width of the rectangle
        height - The height of the rectangle
        color - The color of the rectangle
      • Rectangle

        public Rectangle​(int centerX,
                         int centerY,
                         int width,
                         int height,
                         java.lang.String color)
        Create a new Rectangle element with a certain color by name (see Hue for list of all valid names)
        
         // Create a new red Rectangle centered at (100, 100) with a width of 20 and a height of 30
         Rectangle rectangle = new Rectangle(100, 100, 20, 30, "red");
         
        Parameters:
        centerX - The X-position of the rectangle
        centerY - The Y-position of the rectangle
        width - The width of the rectangle
        height - The height of the rectangle
        color - The name of the color (case-insensitive)
    • Method Detail

      • 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<Rectangle>
        Parameters:
        gc - The graphics context to draw the object with
      • 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<Rectangle>
        Parameters:
        gc - The graphics context to draw the object with
      • getWidth

        public int getWidth()
        Gets the width of the rectangle.
        Returns:
        The width of the rectangle in pixels
        See Also:
        setWidth(int), getHeight()
      • setWidth

        public Rectangle setWidth​(int w)
        Sets the width of the rectangle.
        Parameters:
        w - The new width of the rectangle in pixels
        Returns:
        The original object to allow method chaining
        See Also:
        getWidth(), setHeight(int)
      • getHeight

        public int getHeight()
        Gets the height of the rectangle.
        Returns:
        The height of the rectangle in pixels
        See Also:
        getWidth(), setHeight(int)
      • setHeight

        public Rectangle setHeight​(int h)
        Sets the height of the rectangle.
        Parameters:
        h - The new height of the rectangle in pixels
        Returns:
        The original object to allow method chaining
        See Also:
        getHeight(), setWidth(int)