Bonjour a tous,
j'ai un probleme que je ne comprend pas.
Mon application construit une IHM. Suivant les choix effectué par l'utilisateur un traitement est lancé. A la fin de ce traitement, un tableau bi-dimensionnel de Color est retourné.
Mon probleme est quand je souhaite convertir ce tableau en des Jlabel coloré qui remplisse un gridLayout, je n'ai aucun affichage de celui-ci.
voici les morceau utile de mon code:
Donc lorsque l'utilisateur clic sur le bouton "executer", un algorithme ce lance et a la fon de celui-ci, retourne un Color[][]. Ma methode createVisu est alors appelé pour générer a partir de celui-ci un visuel, mais la , rien ....
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 import java.awt.BorderLayout; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; @SuppressWarnings("serial") public class Gestion extends JFrame{ public JButton pasAPas, quitter, executer; public Graphics panneau; public JComboBox choixMethode; public int taille=9; public JPanel panCentre; public JLabel temps; public Gestion(){ // création et initialization de la fenetre super("Polyominos"); setDefaultCloseOperation(EXIT_ON_CLOSE); this.setSize(600, 400); this.setLocationRelativeTo(null); this.setLayout(new BorderLayout()); /************ PARTIE HAUTE ************/ JPanel panG = new JPanel(new FlowLayout()); panG.setBackground(Color.WHITE); executer = new JButton("Executer"); executer.addActionListener(new EcouteurBouton()); panG.add(executer); pasAPas = new JButton("Pas à* pas"); pasAPas.addActionListener(new EcouteurBouton()); quitter = new JButton("Quitter"); quitter.addActionListener(new EcouteurBouton()); panG.add(quitter); choixMethode = new JComboBox(); choixMethode.addItem("Résolution par Aléatoire"); choixMethode.addItem("Résolution par Backtracking"); choixMethode.addItem("Résolution par Recuit"); panG.add(choixMethode); add(panG, BorderLayout.NORTH); /************ AFFICHAGE 2D **************/ panCentre=new JPanel(new GridLayout(taille, taille)); add(panCentre); /************* BAS ********************/ temps=new JLabel("Temps d'execution: 0h00min00s00ms"); add(temps,BorderLayout.SOUTH); /****************************************/ setVisible(true); } public void createVisu(Color[][] tabCoul){ for(Color[] c : tabCoul){ for(Color c1 : c){ JLabel lab = new JLabel(" "); lab.setBackground(c1); panCentre.add(lab); } } } public static void main(String[] args) { new Gestion(); } /** * Fonction qui convertis des millisecondes en heure minute seconde et millisecondes * @param ms millisecondes a convertir */ public void convertTime(long ms){ long millisecondes=ms%1000; ms=ms/1000; long secondes=ms%60; ms=ms/60; long minutes=ms%60; ms=ms/60; long heures=ms; temps.setText("Temps d'execution: "+heures+"h"+minutes+"min"+secondes+"s"+millisecondes+"ms"); } public class EcouteurBouton implements ActionListener { public void actionPerformed(ActionEvent e) { if (e.getSource() == executer) { // lancement de la résolution suivant la methode choisie switch(choixMethode.getSelectedIndex()){ case 0: //methode aléatoire long start = System.currentTimeMillis(); Aleatoire al=new Aleatoire(taille); createVisu(al.resolution()); convertTime(System.currentTimeMillis() - start); break; ..... default: System.out.println("Méthode de résolution inconnu"); System.exit(-1); } } else if (e.getSource() == pasAPas) { } else { // ici bouton quitter System.exit(0); } } } }
Savez ce qui ne va pas dans ce code ?
Je vous remercie d'avance pour votre aide![]()
Partager