- Dec 21, 2000
- 5,280
- 0
- 71
Hey guys! I'm working on a Java assignment and I'm really stuck. I am not sure how to retrieve points from an ArrayList and put them into a Point2D.Double parameter and THEN finally draw lines to connect a list of set points in a JApplet window.
Here's the class that I've written so far. I haven't written up the JApplet program, but I think I can get that...
My instructor said that everything looks good up to the bold part, so I should be OK on the first part. From there on, I'm stuck. I just can't grasp the concepts I need to finish this.
Thanks for any input and your time!
~Travis
Here's the class that I've written so far. I haven't written up the JApplet program, but I think I can get that...
import java.awt.geom.*;
import java.awt.*;
import java.util.ArrayList;
public class Polygon
{
//Initializes the instance variable 'list'.
private ArrayList<Point2D.Double> list;
public Polygon()
{
//Creates an ArrayList called 'list' that stores objects of Point2D.Double type.
list = new ArrayList<Point2D.Double>();
}
//Adds Point2D.Double objects to the array.
public void add(Point2D.Double aPoint)
{
list.add(aPoint);
}
//Draws Point2D.Double objects onto the Applet window.
public void draw(Graphics2D g)
{
for (int i = 0, i < list.size(), i++)
{
//Graphics2D g2 = (Graphics2D) g;
Point2D.Double point1 = new Point2D.Double(list.get(0), list.get(1));
Point2D.Double point2 = new Point2D.Double(list.get(2), list.get(3));
Point2D.Double point3 = new Point2D.Double(list.get(4), list.get(5));
Point2D.Double point4 = new Point2D.Double(list.get(6), list.get(7));
Point2D.Double point5 = new Point2D.Double(list.get(8), list.get(9));
Point2D.Double point6 = new Point2D.Double(list.get(10), list.get(11));
g2.draw();
}
}
My instructor said that everything looks good up to the bold part, so I should be OK on the first part. From there on, I'm stuck. I just can't grasp the concepts I need to finish this.
Thanks for any input and your time!
~Travis