Is it possible to dr开发者_如何学Pythonaw a polyline by passing the method an array list of Point values? something like this:
ArrayList<Point> projectilePoints=new ArrayList<Point>();
Projectile p = new Projectile(11, 17, 73, 37);
for (int i = 0; i < 11; i++) {
Point point = p.getPositionAt(i);
projectilePoints.add(point);
}
g.drawPolyline(projectilePoints, projectilePoints, 11);
What is the correct way to pass in the parameters of x and y points for the polyline?
No, there is no such method takes Arraylist
of Point
reference parameter. The Syntax is,
Graphics.drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
The JavaDpc on Graphics#drawPolyLine
states that you need to pass 2 int arrays that represent the x and y coordinates.
Alternatively, you might use Graphics2d#draw(Shape)
and pass a Path2D
shape, that can be prefilled using your points (e.g. by calling lineTo(x,y)
for all points but the first - for which you might call moveTo(x,y)
).
Call method Graphics2D.drawPolyline
. This method takes an int array of X coordinate values, an int array of Y coordinate values and the number of points.
There is no line drawing method that takes Point
objects, you have to create int arrays of coordinates.
See http://download.oracle.com/javase/1,5.0/docs/api/java/awt/Graphics2D.html
精彩评论