Bonjour,
Dans le code suivant, je ne comprends pas pourquoi la matrice de boutton ne s'affiche pas; pourtant, c'est fait d'une manière identique au autres bouttons...
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 import java.awt.Dimension; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Grille extends JFrame{ JPanel panel; FlowLayout layout; JButton init; JButton start; JButton stop; JButton[][] b; int dim = 10; Grille(){ super(); build(); } void build(){ setTitle("Fourmilière"); setSize(500,700); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setContentPane(getPanel()); setVisible(true); } JPanel getPanel(){ layout = new FlowLayout(); layout.setAlignment(FlowLayout.CENTER); panel = new JPanel(); panel.setLayout(layout); init = new JButton("init"); init.setPreferredSize(new Dimension(75,25)); panel.add(init); start = new JButton("start"); start.setPreferredSize(new Dimension(75,25)); panel.add(start); stop = new JButton("Stop"); stop.setPreferredSize(new Dimension(75,25)); panel.add(stop); b = new JButton[dim][dim]; for(int i=0; i<dim; i++){ for(int j=0; j>dim; j++){ b[i][j] = new JButton(" "); b[i][j].setPreferredSize(new Dimension(10,10)); panel.add(b[i][j]); } } return panel; } }
Partager