Example usage for java.util Timer Timer

List of usage examples for java.util Timer Timer

Introduction

In this page you can find the example usage for java.util Timer Timer.

Prototype

public Timer() 

Source Link

Document

Creates a new timer.

Usage

From source file:Main.java

public static void startThreadStatusTimer(final Thread t1) {
    new Timer().schedule(new TimerTask() {
        @Override/*  ww  w  .ja  va2  s . com*/
        public void run() {
            System.out.println("\t\t\t\t\t\t\t\t\t\tThread(" + t1.getName() + ") state - " + t1.getState());
        }
    }, 0, 1000);
}

From source file:Main.java

public static void doLater(long delay, final Runnable runnable) {
    Timer t = new Timer();
    t.schedule(new TimerTask() {
        @Override/*w w  w.j a  v a  2  s . c o  m*/
        public void run() {
            SwingUtilities.invokeLater(runnable);
        }
    }, delay);
}

From source file:Main.java

public static void timer(TimerTask t) {
    new Timer().schedule(t, 3000);
}

From source file:Main.java

public static void delayToActivity(final Context context, final Class<?> cls, long delay) {
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {

        @Override/*from   ww w . j  a v  a 2  s . c om*/
        public void run() {
            context.startActivity(new Intent(context, cls));
        }
    }, delay);
}

From source file:Main.java

public static Timer setTimeOut(final Runnable runnable, int delayMillis) {
    final Handler handler = new Handler();
    final Timer timer = new Timer();
    timer.schedule(new TimerTask() {

        @Override/* w  ww  .  java2s . com*/
        public void run() {
            handler.post(runnable);
            timer.cancel();
        }
    }, delayMillis);
    return timer;
}

From source file:Main.java

public static Timer setInterval(final Runnable runnable, int delayMillis, int period) {
    final Handler handler = new Handler();
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override//  www  .  j a va  2  s .c om
        public void run() {
            handler.post(runnable);
        }
    }, delayMillis, period);
    return timer;
}

From source file:Main.java

public static void showInputMethodManager(final EditText editText) {
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        public void run() {
            InputMethodManager inputManager = (InputMethodManager) editText.getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(editText, 0);
        }//from w  ww . j  a v a  2  s .  c om
    }, 200);
}

From source file:Main.java

public static void startThreadStatusTimer(final Thread t1, int ms) {
    new Timer().schedule(new TimerTask() {
        @Override//from  ww w  .  ja  va2s. co m
        public void run() {
            System.out.println("\t\t\t\t\t\t\t\t\t\tThread(" + t1.getName() + ") state - " + t1.getState());
        }
    }, 0, ms);
}

From source file:Main.java

public Main(int seconds) {
    timer = new Timer();
    timer.schedule(new ToDoTask(), seconds * 1000);
}

From source file:Main.java

public static void showSoftInput(final Context context, final EditText et) {
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        public void run() {
            InputMethodManager inputManager = (InputMethodManager) context
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(et, 0);
        }//from www  . j av  a2s.  c o m
    }, 998);
}