Re.
Tiens, je te donnes le code que tu veux .. ;o) (après, c'est a toi de l'adapter en fonction de ce que tu veux faire dans ton appli.)
ps: j'ai garder les noms que tu avais donné à tes composants...
/**
* @(#)ChronoIntoLabel.java
*
*
* @author Jean-Baptiste Fromenteau
* @version 1.0.0 2008/4/27
*/
import com.jbf.java.util.Chronometre;
import com.jbf.java.util.event.TimeListener;
import com.jbf.java.util.event.TimeEvent;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.FlowLayout;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/**
*To display time into a JLabel ... ;o)
*
**/
public class ChronoIntoLabel extends JFrame {
/**
*The used chornometre.
*
**/
protected Chronometre chrono = null;
/**
*The JLabel in which we will display the current time.
*
**/
protected JLabel chronoLabel = null;
/**
*The JButton to styart the chronometre.
*
**/
protected JButton start = null;
/**
*The constructor of the frame.
*
**/
public ChronoIntoLabel () {
//Frame properties
this.setTitle("Rotation mentale: Jeu");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
//The chronometre to use
chrono = new Chronometre();
chrono.addTimeListener(new TimeListener() {
//Here (when the time has changed)
public void timeChanged (TimeEvent evt) {
actualizeTime();
}
public void timeStarted (TimeEvent evt) {}
public void timeStoped (TimeEvent evt) {}
public void timeSuspended (TimeEvent evt) {}
public void timeResumed (TimeEvent evt) {}
public void timeReseted (TimeEvent evt) {}
public void hoursChanged (TimeEvent evt) {}
public void minutesChanged (TimeEvent evt) {}
public void secondsChanged (TimeEvent evt) {}
});
//The JLabel which allow us to display time
chronoLabel = new JLabel(" ");
chronoLabel.setAlignmentX(JLabel.CENTER);
this.getContentPane().add(chronoLabel);
//The button to start chronometre
start = new JButton("Start");
start.setPreferredSize(new Dimension(150, 25));
start.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent evt) {
startChrono();
}
});
JPanel panelButton = new JPanel(new FlowLayout());
panelButton.add(start);
this.getContentPane().add(panelButton);
//Automatic size (and show created frame)
this.pack();
this.setVisible(true);
}
/**
*To run the chronometre (this method is called when the start button is pushed).
*
**/
public void startChrono () {
chrono.start();
}
/**
*To actualize the displayed time.
*
**/
public void actualizeTime () {
chronoLabel.setText(chrono.getTime());
}
/**
*Main method (to execute the class).
*
**/
public static void main (String arg[]) {
new ChronoIntoLabel();
}
}
voila .. :p