/Users/lyon/j4p/src/bookExamples/ch26Graphics/draw2d/Arc2d.java
|
1 package bookExamples.ch26Graphics.draw2d;
2
3
4 import java.awt.*;
5
6 public class Arc2d extends Shape {
7 private int x1 = 0;
8 private int y1 = 0;
9 private int w = 1;
10 private int h = 1;
11 private int xc = 0;
12 private int yc = 0;
13 private int startAngle = 90;
14 private int arcAngle = 180;
15 private Line2d plane = null;
16
17 public Arc2d(int _x1, int _y1, int _x2, int _y2) {
18 x1 = _x1;
19 y1 = _y1;
20 w = Math.abs(_x2 - x1);
21 h = Math.abs(_y2 - y1);
22 int _x1PluswOn2 = _x1 + w / 2;
23 plane = new Line2d(_x1PluswOn2, _y1, _x1PluswOn2, _y1 + h);
24 xc = x1 + w / 2;
25 yc = y1 + h / 2;
26 }
27
28 public void paint(Graphics g) {
29 g.drawArc(x1, y1, w, h, startAngle, arcAngle);
30 plane.paint(g);
31 g.fillOval(xc, yc, 2, 2);
32 g.drawString("(" + xc + "," + yc + ")", xc + 3, yc + 3);
33 }
34 }
35