Java tutorial
//package com.java2s; /* * SwingBugUtilities.java * * Created on March 30, 2007, 12:27 AM * * Copyright 2006-2007 Nigel Hughes * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at http://www.apache.org/ * licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Timer; public class Main { /** * Runs the supplied class after a certain period of time, the thread * will be executed in the EDT. * * @param execute The runnable object whose method will be called after the * specified delay * @param after The delay in ms before the event will be called */ public static Timer invokeAfter(final Runnable execute, int after) { Timer timer = new Timer(after, new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { execute.run(); } }); timer.setRepeats(false); timer.start(); return timer; } }