Skip to content

Commit 8862b84

Browse files
committed
Add default constructor and fix setPosition method.
1 parent c05e9a0 commit 8862b84

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/main/java/main/elements/PolygonElement.java

+27-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222

2323
public class PolygonElement extends Element
2424
{
25+
/**
26+
* Default constructor with empty point list.
27+
*/
28+
protected PolygonElement()
29+
{
30+
this.pointList = new ArrayList<>();
31+
this.borderColor = Color.BLACK;
32+
this.backgroundColor = Color.WHITE;
33+
}
34+
35+
2536
public PolygonElement(List<Point2D> pointList)
2637
{
2738
this(pointList, Color.WHITE);
@@ -77,8 +88,8 @@ public void draw(Graphics2D g)
7788

7889

7990
// ---------------------------------------------------------------------
80-
// Section: Setters and Getters
81-
// ---------------------------------------------------------------------
91+
// Section: Getters
92+
// --------------------------------------------------------------------
8293

8394

8495
@Override
@@ -92,6 +103,11 @@ public Rectangle2D getBounds()
92103
}
93104

94105

106+
// ---------------------------------------------------------------------
107+
// Section: Setters
108+
// ---------------------------------------------------------------------
109+
110+
95111
public void setBackgroundColor(Color color)
96112
{
97113
this.backgroundColor = color;
@@ -104,12 +120,20 @@ public void setBorderColor(Color color)
104120
}
105121

106122

123+
@Override
124+
public void setPosition(Point2D position)
125+
{
126+
super.setPosition(position);
127+
this.buildPolygon();
128+
}
129+
130+
107131
// ---------------------------------------------------------------------
108132
// Section: Variables
109133
// ---------------------------------------------------------------------
110134

111135

112-
private List<Point2D> pointList;
136+
protected List<Point2D> pointList;
113137

114138
private Polygon polygon;
115139

0 commit comments

Comments
 (0)