Java Timer Usage printLoadToConsole(int milliOffset)

Here you can find the source of printLoadToConsole(int milliOffset)

Description

Prints a spinning icon to the console

License

Open Source License

Parameter

Parameter Description
milliOffset a parameter

Declaration

public static void printLoadToConsole(int milliOffset) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Timer;
import java.util.TimerTask;

public class Main {
    private static boolean loading = false;

    /**/*from  w  w w  . j av a  2  s  .  c  o  m*/
     * Prints a spinning icon to the console
     * @param milliOffset
     */
    public static void printLoadToConsole(int milliOffset) {
        loading = true;
        final Timer t = new Timer();
        TimerTask task = new TimerTask() {
            int loop = 0;

            public void run() {
                if (loading) {
                    loop++;
                    if (loop == 1) {
                        System.out.print("\b|");
                    }
                    if (loop == 2) {
                        System.out.print("\b/");
                    }
                    if (loop == 3) {
                        System.out.print("\b-");
                    }
                    if (loop == 4) {
                        System.out.print("\b\\");
                        loop = 0;
                    }
                } else {
                    System.out.print("\b");
                    t.cancel();
                }
            }
        };
        t.schedule(task, 00, milliOffset);
    }
}

Related

  1. getMinIdleTimer()
  2. getQuickSearchTimer()
  3. getSlowTimer()
  4. getTimer(String id)
  5. mayNewTasksBeScheduled(Timer timer)
  6. runRotateKeys()
  7. schedule(final TimerTask task, final int delay, final int period)
  8. schedule(TimerTask task, long delay, long period, String name)
  9. startTimerWithDelayInMillis(TimerTask task, long millisToDelay, long intervalInMillis)