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
 

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.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |