Example usage for java.lang Runnable Runnable

List of usage examples for java.lang Runnable Runnable

Introduction

In this page you can find the example usage for java.lang Runnable Runnable.

Prototype

Runnable

Source Link

Usage

From source file:com.litt.core.security.license.gui.Gui.java

/**
 * Launch the application.//w  w  w  .  j av  a  2 s.c  o m
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Gui window = new Gui();
                window.frame_security.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:iqq.app.IMLauncher.java

/**
 * ??/*  ww  w  .  j  a  va 2 s  .c  o  m*/
 *
 * @param args
 */
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            init();
            startup();
        }
    });
}

From source file:OnlyOneInMethod.java

public static void main(String[] args) {
    final OnlyOneInMethod ooim = new OnlyOneInMethod("obj1");

    Runnable runA = new Runnable() {
        public void run() {
            ooim.doStuff(3);/*from w  w  w  .  jav  a2  s .co m*/
        }
    };

    Thread threadA = new Thread(runA, "threadA");
    threadA.start();

    try {
        Thread.sleep(200);
    } catch (InterruptedException x) {
    }

    Runnable runB = new Runnable() {
        public void run() {
            ooim.doStuff(7);
        }
    };

    Thread threadB = new Thread(runB, "threadB");
    threadB.start();
}

From source file:Main.java

public static void main(String[] arguments) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override//from   www. j av a 2s  . c  om
        public void run() {
            initAndShowGUI();
        }
    });
}

From source file:ProducerComsumer.java

public static void main(String[] args) {
    final ProducerComsumer ch = new ProducerComsumer();

    Runnable runA = new Runnable() {
        public void run() {
            try {
                String str;/*from   w w  w.  j av  a  2s. c  o  m*/
                Thread.sleep(500);

                str = "multithreaded";
                ch.putIn(str);
                str = "programming";
                ch.putIn(str);

                str = "with Java";
                ch.putIn(str);
            } catch (InterruptedException x) {
                x.printStackTrace();
            }
        }
    };

    Runnable runB = new Runnable() {
        public void run() {
            try {
                Object obj;

                obj = ch.takeOut();
                System.out.println("in run() - just took out: '" + obj + "'");

                Thread.sleep(500);

                obj = ch.takeOut();
                System.out.println("in run() - just took out: '" + obj + "'");

                obj = ch.takeOut();
                System.out.println("in run() - just took out: '" + obj + "'");
            } catch (InterruptedException x) {
                x.printStackTrace();
            }
        }
    };

    Thread threadA = new Thread(runA, "threadA");
    threadA.start();

    Thread threadB = new Thread(runB, "threadB");
    threadB.start();
}

From source file:SyncExecExample.java

public static void main(String[] args) {

    final Display display = new Display();
    Shell shell = new Shell(display);

    final Runnable print = new Runnable() {
        public void run() {
            System.out.println("Print from thread: \t" + Thread.currentThread().getName());
        }/*  w  w w .  ja  va  2 s .com*/
    };

    final Thread applicationThread = new Thread("applicationThread") {
        public void run() {
            System.out.println("Hello from thread: \t" + Thread.currentThread().getName());
            display.syncExec(print);
            System.out.println("Bye from thread: \t" + Thread.currentThread().getName());
        }
    };

    shell.setText("syncExec Example");
    shell.setSize(300, 100);

    Button button = new Button(shell, SWT.CENTER);
    button.setText("Click to start");
    button.setBounds(shell.getClientArea());
    button.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            applicationThread.start();
        }
    });

    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {// If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();

}

From source file:TimerRepeating.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    final int time = 500;

    Runnable timer = new Runnable() {
        public void run() {
            Point point = display.getCursorLocation();
            Rectangle rect = shell.getBounds();
            if (rect.contains(point)) {
                System.out.println("In");
            } else {
                System.out.println("Out");
            }/*w ww  .  jav  a2 s  . c o m*/
            display.timerExec(time, this);
        }
    };
    display.timerExec(time, timer);

    shell.setSize(200, 200);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:nayan.netty.client.FileUploadClient.java

public static void main(String args[]) {

    for (int i = 0; i < CLIENT_COUNT; i++) {
        new Thread(new Runnable() {

            @Override/*  w w  w. j av  a2  s .  c o  m*/
            public void run() {
                try {
                    uploadFile();
                } catch (Exception ex) {
                    Logger.getLogger(FileUploadClient.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }).start();

    }

}

From source file:Main.java

public static void main(String[] args) {
    JFrame parentFrame = new JFrame();
    parentFrame.setSize(500, 150);/*from  ww w  . java 2  s.  co m*/
    JLabel jl = new JLabel();
    jl.setText("Count : 0");

    parentFrame.add(BorderLayout.CENTER, jl);
    parentFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    parentFrame.setVisible(true);

    final JDialog dlg = new JDialog(parentFrame, "Progress Dialog", true);
    JProgressBar dpb = new JProgressBar(0, 500);
    dlg.add(BorderLayout.CENTER, dpb);
    dlg.add(BorderLayout.NORTH, new JLabel("Progress..."));
    dlg.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dlg.setSize(300, 75);
    dlg.setLocationRelativeTo(parentFrame);

    Thread t = new Thread(new Runnable() {
        public void run() {
            dlg.setVisible(true);
        }
    });
    t.start();
    for (int i = 0; i <= 500; i++) {
        jl.setText("Count : " + i);
        dpb.setValue(i);
        if (dpb.getValue() == 500) {
            dlg.setVisible(false);
            System.exit(0);

        }
        try {
            Thread.sleep(25);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    dlg.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    final Main it = new Main();

    JFrame frame = new JFrame("Progress Bar Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(it);/*from   w ww  .ja  va2s .c  o m*/
    frame.pack();
    frame.setVisible(true);

    for (int i = MY_MINIMUM; i <= MY_MAXIMUM; i++) {
        final int percent = i;
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    it.updateBar(percent);
                }
            });

            java.lang.Thread.sleep(100);

        } catch (Exception e) {
            ;
        }
    }
}