Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.awt.EventQueue;

import javax.swing.AbstractButton;

import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;

public class Main {
    /**
     * Thread-friendly wrapper method for <code>AbstractButton.setSelected</code>.
     * @param selected
     * @param buttons AbstractButtons to select/deselect
     *
     * @see javax.swing.AbstractButton.setSelected(boolean)
     * @deprecated
     */
    @Deprecated
    public static void setSelected(final boolean selected, final AbstractButton... buttons) {
        Runnable r = new Runnable() {

            public void run() {
                for (AbstractButton button : buttons) {
                    button.setSelected(selected);
                }
            }
        };

        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();
    }
}