Bonsoir à tous !

Je sais que des soucis de ce genre ont été mainte fois postés, mais je fouine sur internet depuis pas mal d'heure maintenant et je commence à devenir fou ...

Au lancement de l'app, mon JPanel est vide, il n'y a que ses contours. Mais après avoir cliqué sur le bouton "Démarrer" mon algo se lance (voyageur de commerce par algo génétique). Dans mon JPanel devrait alors s'afficher le graphe de mon parcours le plus court mais mon JPanel reste vierge !

J'appelle dans ma classe main le setter modifié pour donner un nouveau tableau à Tab_Trajet (instancié au début à null). Et ensuite le repaint() qui je pensais mettrais à jour mon JPanel suivant le nouveau Tab_Trajet masi quedal !

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
 
package view;
 
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
 
public class panelGraphe extends JPanel
{
    private int[] Tab_Trajet = null; // = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ,14} 
    private int[][] Tab_Coord;
 
    public panelGraphe(JPanel panelGraphe)
    {               
        //Panel du Graphe
        this.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        this.setPreferredSize(new Dimension(900, 500));
        this.setMaximumSize(new Dimension(900, 500));
        this.setMinimumSize(new Dimension(900, 500));
    }       
 
    @Override
    public void paint(Graphics g)
    {           
        if(Tab_Trajet != null)
        {
            super.paint(g);
            Tab_Coord = new int[Tab_Trajet.length][2];
            int i = 1, j = 1;
            int x = 50; int y = 50;
            int nb_bloc = (Tab_Trajet.length-1) / 5;
            int size_y = 400 / nb_bloc;
            String point;
 
            while(j <= Tab_Trajet.length)
            {
                point = Integer.toString(j);
                g.drawString(point, x, y-8);
                g.fillRect(x, y, 6, 6);
                Tab_Coord[j-1][0] = x;
                Tab_Coord[j-1][1] = y;
                x += 200;
 
                if(i == 5)
                {
                    y += size_y;
                    x = 50;
                    i = 0;
                }
                i++; j++;
            }
 
            j = 1;
            int X1, Y1, X2, Y2;
            while(j < Tab_Trajet.length)
            {
                X1 = Tab_Coord[j-1][0]; Y1 = Tab_Coord[j-1][1];
                X2 = Tab_Coord[j][0]; Y2 = Tab_Coord[j][1];
                g.drawLine(X1, Y1, X2, Y2);
                j++;
            }
 
            X2 = Tab_Coord[Tab_Trajet.length-1][0];
            Y2 = Tab_Coord[Tab_Trajet.length-1][1];  
            g.setColor(Color.RED);
 
            g.drawLine(50, 50, X2, Y2);
        }
    }
 
    public void setTab_Trajet(int[] Tab_Trajet)
    {
        this.Tab_Trajet = Tab_Trajet;
        this.removeAll();
        this.validate();
        this.repaint();
    }
}