Bonjour, j'ai un gros souci de ralentissement d'une "animation". Pour ceux qui connaissent le jeu de la vie, c'est le même principe.
Bref, je pense que mon code est loin d'être optimisé mais je ne comprend pas le ralentissement aperçu...

Mon Panneau:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package Utils;
 
import javax.swing.*;
import java.awt.*;
import java.awt.Point;
import java.util.*;
import java.util.List;
 
public class Panneau extends JPanel {
 
    public int posX = 0;
    public int posY = 0;
    private List<Point> ar = new ArrayList<>();
    private List<Point> arM = new ArrayList<>();
 
    public Panneau(){
        this.setBackground(Color.WHITE);
 
 
    }
 
    public void start() {
        create(this.ar);
    }
 
    public void  create(List<Point> ar){
        ar.clear();
        ar.add(new Point(15, 50));
        ar.add(new Point(16,49));
        ar.add(new Point(17,49));
        ar.add(new Point(17,50));
        ar.add(new Point(17,51));
        rep(ar,0);
    }
 
 
 
    public void paintComponent(Graphics g){
        g.setColor(Color.WHITE);
        g.fillRect(0,0,1000,1000);
        g.setColor(Color.DARK_GRAY);
        try {
            this.ar.forEach(s -> g.fillRect(s.y*5 , s.x*5 , 5, 5));
        }catch(ConcurrentModificationException c){
            System.out.println("---------------------");
            System.out.println("Aïe");
            System.out.println("---------------------");
        }
    }
 
 
    private void rep(List<Point> ar, int i){
        if(i<1000) {
            System.out.println(i);
            List<Point> arA = new ArrayList<>();
            List<Point> arD = new ArrayList<>();
            List<Point> arN = new ArrayList<>();
            ar.forEach(s -> {
 
                if(s.y<1500 && s.y>0){
                    int V = CompteV(ar,s);
                    if(V<2 || V>3)arD.add(s);
 
 
 
 
 
 
                }
            });
            this.arM.forEach(s -> {
                int V = CompteM(ar,s);
                if(V==3)arA.add(new Point(s.x,s.y));
            });
            this.arM.clear();
            for(Point p : ar){
                if(!arD.contains(new Point(p.x,p.y))){
                    arN.add(p);
                }
            }
            for(Point p : arA){
 
 
                arN.add(p);
            }
            this.ar = arN;
            arA.clear();
            arD.clear();
            ar.clear();
            repaint();
            rep(arN, i + 1);
        }
        repaint();
    }
 
    private int CompteM(List<Point> arV,Point pointM){
        int V = 0;
        if(arV.contains(new Point(pointM.x-1,pointM.y)))V = V+1;
        if(arV.contains(new Point(pointM.x-1,pointM.y+1)))V = V+1;
        if(arV.contains(new Point(pointM.x,pointM.y+1)))V = V+1;
        if(arV.contains(new Point(pointM.x+1,pointM.y+1)))V = V+1;
        if(arV.contains(new Point(pointM.x+1,pointM.y)))V = V+1;
        if(arV.contains(new Point(pointM.x+1,pointM.y-1)))V = V+1;
        if(arV.contains(new Point(pointM.x,pointM.y-1)))V = V+1;
        if(arV.contains(new Point(pointM.x-1,pointM.y-1)))V = V+1;
        return V;
    }
 
    private int CompteV(List<Point> arV,Point pointV){
        int V = 0;
        if(arV.contains(new Point(pointV.x-1,pointV.y)))V = V+1;
        else
            this.arM.add(new Point(pointV.x-1,pointV.y));
        if(arV.contains(new Point(pointV.x-1,pointV.y+1)))V = V+1;
        else
            this.arM.add(new Point(pointV.x-1,pointV.y+1));
        if(arV.contains(new Point(pointV.x,pointV.y+1)))V = V+1;
        else
            this.arM.add(new Point(pointV.x,pointV.y+1));
        if(arV.contains(new Point(pointV.x+1,pointV.y+1)))V = V+1;
        else
            this.arM.add(new Point(pointV.x+1,pointV.y+1));
        if(arV.contains(new Point(pointV.x+1,pointV.y)))V = V+1;
        else
            this.arM.add(new Point(pointV.x+1,pointV.y));
        if(arV.contains(new Point(pointV.x+1,pointV.y-1)))V = V+1;
        else
            this.arM.add(new Point(pointV.x+1,pointV.y-1));
        if(arV.contains(new Point(pointV.x,pointV.y-1)))V = V+1;
        else
            this.arM.add(new Point(pointV.x,pointV.y-1));
        if(arV.contains(new Point(pointV.x-1,pointV.y-1)))V = V+1;
        else
            this.arM.add(new Point(pointV.x-1,pointV.y-1));
 
        return V;
    }
 
    public int getPosX() {
        return posX;
    }
 
    public void setPosX(int posX) {
        this.posX = posX;
    }
 
    public int getPosY() {
        return posY;
    }
 
    public void setPosY(int posY) {
        this.posY = posY;
    }
 
 
 
}
et ma fenetre:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package Utils;
 
        import javax.swing.*;
        import java.awt.*;
 
 
public class Fenetre1 extends JFrame {
 
 
 
 
 
 
    public Fenetre1(Panneau content){
        this.setContentPane(content);
        this.setTitle("arbre");
        this.setSize(1500,1000);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
        content.start();
 
 
    }
 
 
 
 
}