salut,

Je cherche comment je peux faire un petit chrono qui compte jusqu'à 60s.
J'ai trouvé déjà ce code mais, il concerne les heures et les minutes en plus!
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
 
 
import java.awt.event.*;
import javax.swing.*;
 
public class StopWatchRunner extends JLabel 
implements MouseListener, ActionListener {
 
/**
* 
*/
private static final long serialVersionUID = 1L;
 
private long startTime; // Start time of stopwatch.
// (Time is measured in milliseconds.)
 
private boolean running; // True when the stopwatch is running.
 
private Timer timer; // A timer that will generate events
// while the stopwatch is running
 
public StopWatchRunner() {
// Constructor.
super(" jouer! ", JLabel.CENTER);
addMouseListener(this);
}
 
public void actionPerformed(ActionEvent evt) {
// This will be called when an event from the
// timer is received. It just sets the stopwatch
// to show the amount of time that it has been running.
// Time is rounded down to the nearest second.
long time = (System.currentTimeMillis() - startTime) / 1000;
setText("" + time + " s");
}
 
 
public void mousePressed(MouseEvent evt) {
// React when user presses the mouse by
// starting or stopping the stopwatch. Also start
// or stop the timer.
if (running == false) {
// Record the time and start the stopwatch.
running = true;
startTime = evt.getWhen(); // Time when mouse was clicked.
setText(" 0 s");
if (timer == null) {
timer = new Timer(100,this);
timer.start();
}
else
timer.restart();
}
else {
// Stop the stopwatch. Compute the elapsed time since the
// stopwatch was started and display it.
timer.stop();
running = false;
long endTime = evt.getWhen();
double seconds = (endTime - startTime) / 1000.0;
setText("Temps: " + seconds + " sec.");
}
}
 
public void mouseReleased(MouseEvent evt) { }
public void mouseClicked(MouseEvent evt) { }
public void mouseEntered(MouseEvent evt) { }
public void mouseExited(MouseEvent evt) { }
 
 
// end StopWatchRunner
 
}
sans affichage dans un JFrame c'est
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
/* import java.awt.*;
import javax.swing.*;
 
public class TestStopWatch extends JPanel {
 
public void init() {
 
 
 
 
}
 
 
}*/import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.File;
import java.net.MalformedURLException;
import java.text.NumberFormat;
import java.text.ParsePosition;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Vector;
 
import javax.swing.*;
 
 
public class TestStopWatch extends JFrame {
 
public TestStopWatch() {
 
super();
buildchiff();
 
 
}
 
private void buildchiff() {
 
 
setVisible(true);
setTitle("jeu des chiffres et des lettres");
setSize(437,600);
setLocationRelativeTo(null);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setContentPane(buildContentPane());
 
}
 
@SuppressWarnings("deprecation")
private Container buildContentPane() {
JPanel panel=new JPanel();
StopWatchRunner watch = new StopWatchRunner();
watch.setFont( new Font("SansSerif", Font.BOLD, 24) );
watch.setBackground(Color.LIGHT_GRAY);
watch.setForeground( new Color(180,0,0) );
watch.setOpaque(true);
panel.add(watch, BorderLayout.CENTER);
 
return panel;
}
public static void main(String[] args) {
TestStopWatch chr=new TestStopWatch();
}
}
Mon problème c'est que je veux inserer ce chrono(du 1ère code) dans un JPanel qui se trouve dans un JFrame d'une autre classe.
Je veux quelqu'un m'aider pour résoudre ce problème là-dessus ou bien de me donner un petit code qui réalise ce chrono.
merci bien