Java tutorial
//package com.java2s; import java.awt.Component; import java.awt.EventQueue; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; public class Main { /** * Thread-friendly wrapper method for <code>Component.setEnabled</code>. * @param enable * @param components * @deprecated */ @Deprecated public static void setEnabled(final boolean enable, final Component... components) { Runnable r = new Runnable() { public void run() { for (Component comp : components) { comp.setEnabled(enable); } } }; if (EventQueue.isDispatchThread()) { r.run(); return; } runTask(r, true); } /** * Runs a background task * @param r <code>Runnable</code> to execute * @see runTask(Runnable, boolean) * @see java.lang.Runnable * @deprecated */ @Deprecated public static void runTask(Runnable r) { runTask(r, false); } /** * If runOnEDT is true will execute the thread on the Event Dispatch Thread * Otherwise it will use a SwingWorker * @param r <code>Runnable</code> to execute * @param runOnEDT run on Event Dispatching Thread * * @see javax.swing.SwingWorker * @see java.lang.Runnable * @deprecated */ @Deprecated public static void runTask(final Runnable r, boolean runOnEDT) { if (runOnEDT) { SwingUtilities.invokeLater(r); return; } SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { r.run(); return null; } }; worker.execute(); } }