Package shapes

Class Square

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Shape>, Movable
    Direct Known Subclasses:
    Rectangle

    public class Square
    extends SurfaceShape
    Class that represent square shape.
    See Also:
    Serialized Form
    • Field Detail

      • upLeft

        protected Point upLeft
      • side

        protected int side
    • Constructor Detail

      • Square

        public Square()
      • Square

        public Square​(Point upLeft,
                      int side)
      • Square

        public Square​(Point upLeft,
                      int side,
                      java.awt.Color edgeColor,
                      java.awt.Color interiorColor)
    • Method Detail

      • draw

        public void draw​(java.awt.Graphics graphics)
        Draw square.
        Specified by:
        draw in class Shape
        Parameters:
        graphics -
      • equals

        public boolean equals​(java.lang.Object obj)
        Check if two squares are equal depend on their up left points and side lengths.
        Overrides:
        equals in class java.lang.Object
      • compareTo

        public int compareTo​(Shape shape)
        Compares two squares depend on their surface.
      • toString

        public java.lang.String toString()
        Print square values.
        Overrides:
        toString in class java.lang.Object
      • moveTo

        public void moveTo​(int x,
                           int y)
        Move up left point of square to forwarded coordinates.
        Parameters:
        x - Represent x coordinate of place where to move.
        y - Represent y coordinate of place where to move.
      • selected

        public void selected​(java.awt.Graphics graphics)
        Select square.
        Specified by:
        selected in class Shape
        Parameters:
        graphics -
      • containsClick

        public boolean containsClick​(int x,
                                     int y)
        Check if this square contains user click.
        Specified by:
        containsClick in class Shape
        Parameters:
        x - Represent x coordinate of user click.
        y - Represent y coordinate of user click.
        Returns:
        Boolean that indicate if this square contains click.
      • clone

        public Square clone()
        Create new instance of this square.
        Overrides:
        clone in class java.lang.Object
      • fillUpShape

        public void fillUpShape​(java.awt.Graphics graphics)
        Fill up square.
        Specified by:
        fillUpShape in class SurfaceShape
        Parameters:
        graphics -
      • surface

        public int surface()
        Calculate surface of square.
        Returns:
        surface of square.
      • diagonal

        public Line diagonal()
        Calculate diagonal of square.
        Returns:
        Line which represent square diagonal.
      • getUpLeft

        public Point getUpLeft()
      • setUpLeft

        public void setUpLeft​(Point upLeft)
      • getSide

        public int getSide()
      • setSide

        public void setSide​(int side)