这里是三角
public class Triangle {
private Point[] coords;
// Null object constructor
public Triangle() {
this.coords = null;
}
// Constructor with point array
public Triangle(Point[] coords) {
this.coords = coords;
}
// Constructor with multiple points
public Triangle(Point a, Point b, Point c) {
this.coords = new Point[3];
coords[0] = a;
coords[1] = b;
coords[2] = c;
}
// The actual paint method
public void paint(Graphics arg0) {
// Setup local variables to hold the coordinates
int[] x = new int[3];
int[] y = new int[3];
// Loop through our points
for (int i = 0; i < coords.length; i++) {
Point point = coords[i];
// Parse out the coordinates as integers and store to our local variables
x[i] = Double.valueOf(point.getX()).intValue();
y[i] = Double.valueOf(point.getY()).intValue();
}
// Actually commit to our polygon
arg0.drawPolygon(x, y, 3);
}
}
不确定的示例类究竟这个类应该被延长,因此没有被标记为一个覆盖或任何东西,它缺少制定者和存取,但你应该能够使其工作。
真棒,这正是我需要的人。我想我现在明白如何制作它。非常感谢:D – user1780311
为什么'x [i] = Double.valueOf(point.getX())。intValue();'?为什么不''x [i] = point.getX();'? – Mordechai