Java help!

jamesbond007

Diamond Member
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...

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
 

Cooler

Diamond Member
Mar 31, 2005
3,835
0
0
BTW there is already a polygon class.
and use array of int x,y would be better then java object.


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(i), list.get(i+1));

g2.draw();
}
}
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: Cooler
BTW there is already a polygon class.
and use array of int x,y would be better then java object.


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(i), list.get(i+1));

g2.draw();
}
}
Going by his original hardcoded example, I'd guess your code is wrong too ;)

But as for this g2.draw(), I wouldn't know if he wants it inside or outside the loop 'cause I don't understand it :eek:
 

jamesbond007

Diamond Member
Dec 21, 2000
5,280
0
71
Thanks for the heads up everyone!

Like I said, I don't know everything of what I'm doing. It's due in exactly 3 hours, so I have to get cramming! Even if there is a Polygon class, I have to make my own that does my own instructions.