How to put my Circles in an array from the smallest X and Y position on the screen to the largest X and Y position?
I tried several solutions but nothing helped so far.
This is the code I'm currently using:
for (int i = 0; i < 36; i++) {
Circle abcd = (Circle) root.getChildren().get(35-i);
Circle cir1 = (Circle) root.getChildren().get(i);
if(abcd.getCenterY() < cir1.getCenterY())
if ( abcd.getCenterX() < cir1.getCenterX() ) {
abcd = cir1;
}
chronologisch.add(abcd);
}
chronologisch is an ArrayList in this context.
With this code i get the following output when debugging:
0 = {Circle@2967} "Circle[centerX=305.0, centerY=225.0, radius=15.0, fill=0xffe100ff]" 1 = {Circle@2968} "Circle[centerX=260.0, centerY=225.0, radius=15.0, fill=0x00bbe2ff]" 2 = {Circle@2969} "Circle[centerX=215.0, centerY=225.0, radius=15.0, fill=0x00bbe2ff]" 3 = {Circle@2970} "Circle[centerX=170.0, centerY=225.0, radius=15.0, fill=0xffe100ff]" 4 = {Circle@2971} "Circle[centerX=125.0, centerY=225.0, radius=15.0, fill=0xffe100ff]" 5 = {Circle@2972} "Circle[centerX=80.0, centerY=225.0, radius=15.0, fill=0x91eb4cff]" 6 = {Circle@2973} "Circle[centerX=305.0, centerY=180.0, radius=15.0, fill=0xff7300ff]" 7 = {Circle@2974} "Circle[centerX=260.0, centerY=180.0, radius=15.0, fill=0xe02ca2ff]" 8 = {Circle@2975} "Circle[centerX=215.0, centerY=180.0, radius=15.0, fill=0xff6d7eff]" 9 = {Circle@2925} "Circle[centerX=170.0, centerY=180.0, radius=15.0, fill=0x91eb4cff]" 10 = {Circle@2976} "Circle[centerX=305.0, centerY=135.0, radius=15.0, fill=0xff7300ff]" 11 = {Circle@2977} "Circle[centerX=260.0, centerY=135.0, radius=15.0, fill=0x00bbe2ff]" 12 = {Circle@2978} "Circle[centerX=215.0, centerY=135.0, radius=15.0, fill=0x00bbe2ff]" 13 = {Circle@2979} "Circle[centerX=170.0, centerY=135.0, radius=15.0, fill=0xffe100ff]" 14 = {Circle@2980} "Circle[centerX=125.0, centerY=135.0, radius=15.0, fill=0xe02ca2ff]" 15 = {Circle@2981} "Circle[centerX=80.0, centerY=135.0, radius=15.0, fill=0xff7300ff]" 16 = {Circle@2982} "Circle[centerX=305.0, centerY=90.0, radius=15.0, fill=0xff6d7eff]" 17 = {Circle@2983} "Circle[centerX=260.0, centerY=90.0, radius=15.0, fill=0xe02ca2ff]" 18 = {Circle@2984} "Circle[centerX=215.0, centerY=90.0, radius=15.0, fill=0x91eb4cff]" 19 = {Circle@2985} "Circle[centerX=170.0, centerY=90.0, radius=15.0, fill=0xff7300ff]" 20 = {Circle@2986} "Circle[centerX=125.0, centerY=90.0, radius=15.0, fill=0xff7300ff]" 21 = {Circle@2980} "Circle[centerX=125.0, centerY=135.0, radius=15.0, fill=0xe02ca2ff]"
as you can see the values are not in chronological order.
Thanks in advance!