Bonjour à tous,

Alors voici mon code

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
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.Timer;
 
public class CompteEstBon extends JFrame{
    private static String[] plaquettes={"1","1","2","2","3","3","4","4","5","5","6","6","7","7","8","8","9","9","10","10","25","25","50","50","75","75","100","100"};
    private static int time = 5;
    public CompteEstBon(){
        super("Compte est bon");
        JPanel jpFond = new JPanel();
        BorderLayout bl = new BorderLayout();
        jpFond.setLayout(bl);
 
        int Total = (100 + (int)(Math.random()*(999-100))+1);
        Random r = new Random(System.currentTimeMillis());
 
        int position1 = r.nextInt(plaquettes.length);
        String nb1 = plaquettes[position1];
 
        int position2 = r.nextInt(plaquettes.length);
        String nb2 = plaquettes[position2];
 
        int position3 = r.nextInt(plaquettes.length);
        String nb3 = plaquettes[position3];
 
        int position4 = r.nextInt(plaquettes.length);
        String nb4 = plaquettes[position4];
 
        int position5 = r.nextInt(plaquettes.length);
        String nb5 = plaquettes[position5];
 
        int position6 = r.nextInt(plaquettes.length);
        String nb6 = plaquettes[position6];
 
        chrono();
 
 
        JPanel jpNord = new JPanel();
        jpNord.add(new JButton(nb1));
        jpNord.add(new JButton(nb2));
        jpNord.add(new JButton(nb3));
        jpNord.add(new JButton(nb4));
        jpNord.add(new JButton(nb5));
        jpNord.add(new JButton(nb6));
        jpFond.add(jpNord,BorderLayout.NORTH);
 
        JPanel jpEst = new JPanel();
        jpEst.add(new JButton(String.valueOf(Total)));
        jpFond.add(jpEst,BorderLayout.EAST);
 
        JPanel jpOuest = new JPanel();
        jpOuest.add(new JLabel(String.valueOf(time)));
        jpFond.add(jpOuest,BorderLayout.WEST);
 
        this.setContentPane(jpFond);
        this.pack();
        this.setVisible(true);
    }
 
    public void chrono(){
 
        Timer chrono = new Timer();
        chrono.schedule(new TimerTask(){
 
            @Override
            public void run(){
 
                if(time == 0){
                    cancel();
                    System.out.println("Fin du jeu");
                }
 
                time--;
            }
        }, 1000,1000);
 
    }
}
Et mon problème est le suivant :
J'ai mis "time" dans un JLabel, sauf que ce dernier se décrémente à chaque fois de un dans la méthode "chrono". Problème, dans mon JLabel, il reste toujours à 5 et ne diminue pas. Une solution ?