/Users/lyon/j4p/src/bookExamples/ch26Graphics/draw2d/Line2d.java
|
1 package bookExamples.ch26Graphics.draw2d;
2
3
4 import java.awt.*;
5
6 public class Line2d extends Shape {
7 int x1 = 0;
8 int y1 = 0;
9 int x2 = 1;
10 int y2 = 1;
11
12 public Line2d(int _x1, int _y1, int _x2, int _y2) {
13 x1 = _x1;
14 y1 = _y1;
15 x2 = _x2;
16 y2 = _y2;
17 }
18
19 public Line2d(Vec2d v1, Vec2d v2) {
20 x1 = (int) v1.v[0];
21 y1 = (int) v1.v[1];
22 x2 = (int) v2.v[0];
23 y2 = (int) v2.v[1];
24 }
25
26 public void paint(Graphics g) {
27 g.drawLine(x1, y1, x2, y2);
28 }
29
30 public String toString() {
31 return
32 "x1,y1,x2,y2=" + x1 + "," + y1 + "," + x2 + "," + y2;
33 }
34 }
35