Package shapes
Class Square
- java.lang.Object
-
- shapes.Shape
-
- shapes.SurfaceShape
-
- shapes.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 Summary
Fields Modifier and Type Field Description private static long
serialVersionUID
protected int
side
protected Point
upLeft
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Square
clone()
Create new instance of this square.int
compareTo(Shape shape)
Compares two squares depend on their surface.boolean
containsClick(int x, int y)
Check if this square contains user click.Line
diagonal()
Calculate diagonal of square.void
draw(java.awt.Graphics graphics)
Draw square.boolean
equals(java.lang.Object obj)
Check if two squares are equal depend on their up left points and side lengths.void
fillUpShape(java.awt.Graphics graphics)
Fill up square.int
getSide()
Point
getUpLeft()
void
moveTo(int x, int y)
Move up left point of square to forwarded coordinates.void
selected(java.awt.Graphics graphics)
Select square.void
setSide(int side)
void
setUpLeft(Point upLeft)
int
surface()
Calculate surface of square.java.lang.String
toString()
Print square values.-
Methods inherited from class shapes.SurfaceShape
getInteriorColor, setInteriorColor
-
Methods inherited from class shapes.Shape
getColor, isSelected, setColor, setSelected
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
upLeft
protected Point upLeft
-
side
protected int side
-
-
Method Detail
-
draw
public void draw(java.awt.Graphics graphics)
Draw square.
-
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 classjava.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 classjava.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.
-
containsClick
public boolean containsClick(int x, int y)
Check if this square contains user click.- Specified by:
containsClick
in classShape
- 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 classjava.lang.Object
-
fillUpShape
public void fillUpShape(java.awt.Graphics graphics)
Fill up square.- Specified by:
fillUpShape
in classSurfaceShape
- 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)
-
-