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
| import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.Timer;
public class Main extends JFrame implements ActionListener{
int compteur = 0;
JLabel label = new JLabel("");
public Main(){
Timer t = new Timer(500,this);//this -> ActionListener
t.start();
this.setSize(100,100);
this.setContentPane(label);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {//Activé par le Timer
label.setText(compteur+"");
compteur++;
}
public static void main(String[] args){
new Main();
}
} |