import javax.swing.*; import java.awt.*; import java.awt.event.*; public class TimerTest extends JFrame implements ActionListener { int counter = 0; JLabel theLabel; public TimerTest() { super("timer test"); //Create a timer that will call 'this' once per second. Timer t = new Timer( 1000, this ); //Start the timer. t.start(); //A label that will be updated by the timer. theLabel = new JLabel( "", theLabel.CENTER ); getContentPane().add( theLabel, BorderLayout.CENTER); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setSize(300, 200); setVisible(true); } public void actionPerformed( ActionEvent e ) { //This method is called when the timer goes off. //Update the label. theLabel.setText( "Det har nu gått " + counter++ + " sekunder" ); } public static void main(String args[]) { new TimerTest(); } }