Utils.java :  » Game » dynamicbuttonsoccer » common » Java Open Source

Java Open Source » Game » dynamicbuttonsoccer 
dynamicbuttonsoccer » common » Utils.java

package common;

import java.lang.reflect.InvocationTargetException;
import javax.swing.SwingUtilities;

/**
 *
 * @author xissburg
 */
public class Utils
{
    /**
     * Runs the given Runnable in the Event Dispatch Thread
     * 
     * @param runnable
     */
    public static void runInEDT(Runnable runnable)
    {
        runInEDT(runnable, false);
    }

    public static void runInEDT(Runnable runnable, boolean wait)
    {
        if(SwingUtilities.isEventDispatchThread())
            runnable.run();
        else
        {
            if(wait)
                try {
                    SwingUtilities.invokeAndWait(runnable);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                } catch (InvocationTargetException ex) {
                    ex.printStackTrace();
                }
            else
                SwingUtilities.invokeLater(runnable);
        }
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.