Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Outside the loop: Define two arrays for the x and y values and an index to use with them.
Inside the loop: assign the current POINT's x and y values in the arrays and increment the index:
x[index] = POINT's x value
y[index] = POINT's y value
index++
If you don't understand my answer, don't ignore it, ask a question.
hello
I apologize as we move forward I can not see me for help
< int[] x = null ; int[] y = null ; int index = 0; for (POINTS pnt : POLYGON) { x[index] = pnt.getX(); y[index++] = pnt.getY(); } >
The x an y arrays should be defined the same size as the POLYGON collection.This is copied from your code:int n = POLYGON.size() ; int[] x = new int[n]; int[] y = new int[n];
Now look at the steps in post #15.
You need to recognize when the id for the POINTs object changes.
When it changes then you are at the end of the points for the last id and need to create a Polygon object that has all the points that have been saved in the x and y arrays and save that new Polygon object in the polygons array.
If you don't understand my answer, don't ignore it, ask a question.
hello
I apologize to recognize when the id changes should I use if () {}
or how do I know when the id changes and pass the points array
and draw thank you in advance
When the value returned by the getID() method changes.how do I know when the id changes
If you don't understand my answer, don't ignore it, ask a question.
You need an int variable that keeps track of the id of the POINTS. It should start at 1 to match the id of the first POINTS in the POLYGON collection.
If you don't understand my answer, don't ignore it, ask a question.
Please explain.how do I save the collection
What variable contains a reference to the collection?
What do you mean by "save"? Write it to disk file or put it into a database?
If you don't understand my answer, don't ignore it, ask a question.
hello
I'm sorry not to save but to pass the points based
on the id to polygons and then draw that is the question
If it is too complicated now to separate the x,y pairs into separate Polygons based on their id, put all of the x,y points into one Polygon object. Change the loop in the paintComponent() method that loops through the array of Polygon obects to only draw the first polygon (which will have the points for all 4 polygons).
When that is working, then come back to the logic that will detect when the next POINTS from the POLYGON collection has a different id from the last POINTS object and use that to create a Polygon object for the x,y points saved so far and to reset the pointer to start saving the x,y points for the next id.
If you don't understand my answer, don't ignore it, ask a question.