1 import java.awt.Color;
2 import java.awt.Graphics2D;
3 import java.awt.Rectangle;
4 import java.awt.geom.Line2D;
5
6 public class ItalianFlag
7 {
8 private int xLeft;
9 private int yTop;
10 private int width;
11
12 public ItalianFlag(int x, int y, int aWidth)
13 {
14 xLeft = x;
15 yTop = y;
16 width = aWidth;
17 }
18
19 public void draw(Graphics2D g2)
20 {
21 Rectangle leftRectangle = new Rectangle(
22 xLeft, yTop,
23 width / 3, width * 2 / 3);
24 Rectangle rightRectangle = new Rectangle(
25 xLeft + 2 * width / 3, yTop,
26 width / 3, width * 2 / 3);
27 Line2D.Double topLine = new Line2D.Double(
28 xLeft + width / 3, yTop,
29 xLeft + width * 2 / 3, yTop);
30 Line2D.Double bottomLine = new Line2D.Double(
31 xLeft + width / 3, yTop + width * 2 / 3,
32 xLeft + width * 2 / 3, yTop + width * 2 / 3);
33
34 g2.setColor(Color.GREEN);
35 g2.fill(leftRectangle);
36 g2.setColor(Color.RED);
37 g2.fill(rightRectangle);
38 g2.setColor(Color.BLACK);
39 g2.draw(topLine);
40 g2.draw(bottomLine);
41 }
42 }