Java tutorial
//package com.java2s; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Timer; public class Main { public static void runTimer(int duration, final Runnable run) { Timer t = new Timer(duration, new ActionListener() { public void actionPerformed(ActionEvent e) { run.run(); } }); t.setRepeats(false); t.start(); } }