01: /*
02: * Copyright (C) 2001, 2002 Robert MacGrogan
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: *
19: * $Archive: SourceJammer$
20: * $FileName: Spinner.java$
21: * $FileID: 4324$
22: *
23: * Last change:
24: * $AuthorName: Rob MacGrogan$
25: * $VerID: 8778$
26: * $Date: 4/23/03 5:23 PM$
27: * $Comment: Replaced GPL header with LGPL header.$
28: *
29: */
30: package org.sourcejammer.util;
31:
32: import java.io.PrintStream;
33:
34: /**
35: * Title: $FileName: Spinner.java$
36: * @author $AuthorName: Rob MacGrogan$
37: * @version $VerNum: 2$
38: * $KeyWordsOff: $<br><br>
39: *
40: *
41: * Displays a spinner in a print stream.
42: */
43: public class Spinner {
44:
45: private PrintStream out = null;
46: private String[] spins = { "|", "/", "-", "\\" };
47: private int lastSpin = 4;
48: private static final int MAX_SPINS = 4;
49:
50: public Spinner(PrintStream out) {
51: this .out = out;
52: out.print(spins[0]);
53: lastSpin = 0;
54: }
55:
56: public void spin() {
57: int this Spin = lastSpin + 1;
58: if (this Spin >= MAX_SPINS)
59: this Spin = 0;
60: out.print("\b" + spins[this Spin]);
61: lastSpin = this Spin;
62: }
63:
64: public static void main(String[] args) {
65: try {
66: System.out.print("\r\n\r\nLet's spin: ");
67: Spinner spin = new Spinner(System.out);
68: for (int i = 0; i < 200; i++) {
69: for (int j = 0; j < 10000000; j++) {
70: }
71: spin.spin();
72: }
73: } catch (Throwable thr) {
74: thr.printStackTrace();
75: }
76: }
77:
78: }
|