hello
how do I save id, x, y array polygons
I thank you in advance
Printable View
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++
hello
I apologize as we move forward I can not see me for help
Code java:< 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: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.
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.Quote:
how do I know when the id changes
hello
I'm sorry I can not go on I thank you in advance.:confused:
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.
hello
I'm sorry but how do I save the collection :confused:
Please explain.Quote:
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?
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.