I just answer a similar question in another forum for a question about SwingWorker:
import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; import javax.swing.Timer; public class Main extends JFrame { private JLabel label; private Executor executor = Executors.newCachedThreadPool(); private Timer timer; private int delay = 1000;
ps : @trashgod helps me a month ago to figure out how to deal with SwingWorker ( Cannot get ArrayIndexOutOfBoundsException from the future <?> and SwingWorker if the thread launches Executor ), so thanks to him.
EDIT: Code fixed. Thanks @ Hovercraft Full Of Eels
source share