Mega Code Archive

 
Categories / Java Tutorial / Development
 

Swing also provide a Timer class A Timer object will send an ActionEvent to the registered ActionListener

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Timer; public class Main implements ActionListener {   Timer t = new Timer(1000, this);   Main() {     t.start();   }   public void actionPerformed(ActionEvent e) {     System.out.println("working");   }   public static void main(String args[]) {     Main main = new Main();   } }