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 longserialVersionUIDprotected intsideprotected PointupLeft
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Squareclone()Create new instance of this square.intcompareTo(Shape shape)Compares two squares depend on their surface.booleancontainsClick(int x, int y)Check if this square contains user click.Linediagonal()Calculate diagonal of square.voiddraw(java.awt.Graphics graphics)Draw square.booleanequals(java.lang.Object obj)Check if two squares are equal depend on their up left points and side lengths.voidfillUpShape(java.awt.Graphics graphics)Fill up square.intgetSide()PointgetUpLeft()voidmoveTo(int x, int y)Move up left point of square to forwarded coordinates.voidselected(java.awt.Graphics graphics)Select square.voidsetSide(int side)voidsetUpLeft(Point upLeft)intsurface()Calculate surface of square.java.lang.StringtoString()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:
equalsin 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:
toStringin 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:
containsClickin 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:
clonein classjava.lang.Object
-
fillUpShape
public void fillUpShape(java.awt.Graphics graphics)
Fill up square.- Specified by:
fillUpShapein 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)
-
-