Skip to content

Commit aa248dc

Browse files
committed
added ColorPolygon
1 parent da0053b commit aa248dc

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

ch16/ColorPolygon.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.awt.Color;
2+
import java.awt.Graphics;
3+
import java.awt.Polygon;
4+
5+
/**
6+
* Specialization of Polygon that has a color and the ability to draw itself.
7+
*/
8+
public class ColorPolygon extends Polygon {
9+
10+
public Color color;
11+
12+
/**
13+
* Creates an empty polygon.
14+
*/
15+
public ColorPolygon() {
16+
super();
17+
color = Color.GRAY;
18+
}
19+
20+
/**
21+
* Draws the polygon on the screen.
22+
*
23+
* @param g graphics context
24+
*/
25+
public void draw(Graphics g) {
26+
g.setColor(color);
27+
g.fillPolygon(this);
28+
}
29+
30+
}

0 commit comments

Comments
 (0)