Java Swing Timer create

Description

Java Swing Timer create

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;

public class Main {
   public static void main(String[] argv) {
      ActionListener task = new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            System.out.println(e);
         }// w  ww.  j av a 2 s . co  m
      };
      Timer timer = new Timer(500, task); // fire every half second
      timer.setInitialDelay(2000); // first delay 2 seconds
      timer.setRepeats(false);
      timer.start();
   }
}



PreviousNext

Related