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:Main.java

public static void main(String... args) {
    //Anonymous ways
    Runnable r1 = new Runnable() {
        public void run() {
            System.out.println("Hello world from " + Thread.currentThread().getName());
        }/*from w  w  w  .  j a va 2s  .c  om*/
    };

    // Runnable is already a functional interface
    Runnable r2 = () -> System.out.println("Hello world  from " + Thread.currentThread().getName());
    (new Thread(r1)).start();
    (new Thread(r2)).start();

}

From source file:Main.java

public static void main(String[] args) {
    try {//from   ww  w.j  ava2  s.  com
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                System.out.println("Hello World on " + Thread.currentThread());
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("Finished on " + Thread.currentThread());
}

From source file:Main.java

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            JFrame frame = new ImageProcessingFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);/*from ww w.jav  a  2 s .  co m*/
        }
    });
}

From source file:EventDispatchThread.java

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            creatGUI();/*from   w  w w.  j av  a 2s  . c  o  m*/
        }
    });
}

From source file:Main.java

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            Main mainForm = new Main();
            mainForm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            mainForm.setSize(250, 250);/*from   www .j a  v a  2  s  .  c o  m*/

            Cursor cursor = new Cursor(Cursor.HAND_CURSOR);
            mainForm.setCursor(cursor);

            mainForm.pack();
            mainForm.setVisible(true);
        }
    });
}

From source file:TimerSample.java

public static void main(String args[]) {
    Runnable runner = new Runnable() {
        public void run() {
            ActionListener actionListener = new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    System.out.println("Hello World Timer");
                }/*from   w w  w  .  j a  v a2  s. c  o  m*/
            };
            Timer timer = new Timer(500, actionListener);
            timer.start();
        }
    };
    EventQueue.invokeLater(runner);
}

From source file:TimerSample.java

public static void main(String args[]) {
    Runnable runner = new Runnable() {
        public void run() {
            Timer.setLogTimers(true);
            ActionListener actionListener = new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    System.out.println("Hello World Timer");
                }/*  w w  w  .ja va 2 s . com*/
            };
            Timer timer = new Timer(500, actionListener);
            timer.start();
        }
    };
    EventQueue.invokeLater(runner);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JTextField textfield = new JTextField(10);

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            textfield.requestFocus();/*from w w  w .j a v a 2  s .co m*/
        }
    });
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    final JTextField textfield = new JTextField(10);

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            textfield.requestFocus();//from  w  ww  .  ja  va 2  s  . c o m
        }
    });

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Runnable myRunnable = new Runnable() {
        @Override/* w  w  w .j  av a 2s .  com*/
        public void run() {
            try {
                System.out.println("Start: " + Thread.currentThread().getName());
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    };
    Thread one = new Thread(myRunnable);
    Thread two = new Thread(myRunnable);
    one.start();
    two.start();

    List<Thread> threads = getThreadsFor(myRunnable);
    for (Thread thread : threads)
        System.out.println("Found: " + thread.getName());
}