Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*; // for GregorianCalendar
- public class BigTime {
- public static void main(String[] args) {
- /**
- * Program: BigTime.java
- * Purpose: Command line Digital clock with large scrolling display
- * Creator: Chris Clarke
- * Created: 17-18.01.2011
- * Modified: 19.10.2012 add Thread.sleep(), reposition display
- */
- // method call to create digits
- createDigits();
- while (true) {
- strTime = "";
- // clear screen
- for (int i = 0; i < 25; i++) {
- // slow down scrolling
- slowItDown(40);
- System.out.println();
- } // end for
- // create instance of calendar
- GregorianCalendar now = new GregorianCalendar();
- int hour = now.get(Calendar.HOUR);
- int amPm = now.get(Calendar.AM_PM);
- int minute = now.get(Calendar.MINUTE);
- if (hour == 0) {
- hour = 12;
- } // end if
- // "01", "02" etc instead of "1", "2" etc
- if (hour < 10) {
- strTime += " "; // add a space
- // or strTime += "0"; // or add a zero
- } // end if
- strTime += hour;
- strTime += ":";
- // "00", "01", "02" etc instead of "0", "1", "2"
- if (minute<10) {
- strTime += "0";
- } // end if
- strTime += minute;
- // method call to display large characters
- displayLetters( amPm);
- int newMinute;
- // loop until newMinute changes
- do {
- GregorianCalendar later = new GregorianCalendar();
- // create new instance of calendar
- newMinute = later.get(Calendar.MINUTE);
- // get current minute
- } while (newMinute == minute);
- } // end while
- } // end main
- public static void slowItDown(int amount) {
- try {
- Thread.sleep(amount);
- } catch (Exception x) {
- System.out.println("Caught Exception! " + x.getMessage());
- } // end try...catch
- } // end slowItDown
- public static void displayLetters( int amPm) {
- String ch = "";
- int digitNum = 0;
- for (int row = 0; row < 7; row++) {
- // slow down scrolling of text
- slowItDown(40);
- System.out.print("\t\t");
- for (int i = 0; i < 5; i++) {
- // separate into 5 Strings
- ch = strTime.substring(i, i+1);
- if (i == 2) {
- // colon
- digitNum = 11;
- } else {
- if (ch.equals(" " )) {
- // space
- digitNum = 10;
- } else {
- // number 0-9
- digitNum = Integer.parseInt(ch);
- } // end if
- } // end if
- System.out.print(digit[digitNum][row]);
- // add space
- System.out.print(" ");
- } // end for i
- if (amPm == 0) {
- // "a" for "am"
- digitNum = 12;
- } else {
- // "p" for "pm"
- digitNum = 13;
- } // end if
- System.out.print(digit[digitNum][row]);
- System.out.println(digit[14][row]); // "m" for am/pm
- } // end for row
- for (int j = 0; j < 9; j++) { // move text up 9 rows
- // slow down scrolling of text
- slowItDown(40);
- System.out.println(); // new line
- } // end for j
- } // end displayLargeCharacters
- public static void createDigits() {
- digit[0][0] = " 888 ";
- digit[0][1] = "8 8";
- digit[0][2] = "8 88";
- digit[0][3] = "8 8 8";
- digit[0][4] = "88 8";
- digit[0][5] = "8 8";
- digit[0][6] = " 888 ";
- digit[1][0] = " 8 ";
- digit[1][1] = " 88 ";
- digit[1][2] = " 8 ";
- digit[1][3] = " 8 ";
- digit[1][4] = " 8 ";
- digit[1][5] = " 8 ";
- digit[1][6] = " 888";
- digit[2][0] = " 888 ";
- digit[2][1] = "8 8";
- digit[2][2] = " 8";
- digit[2][3] = " 8 ";
- digit[2][4] = " 8 ";
- digit[2][5] = " 8 ";
- digit[2][6] = "88888";
- digit[3][0] = " 888 ";
- digit[3][1] = "8 8";
- digit[3][2] = " 8";
- digit[3][3] = " 888";
- digit[3][4] = " 8";
- digit[3][5] = "8 8";
- digit[3][6] = " 888 ";
- digit[4][0] = " 8 ";
- digit[4][1] = " 88 ";
- digit[4][2] = " 8 8 ";
- digit[4][3] = "8 8 ";
- digit[4][4] = "88888";
- digit[4][5] = " 8 ";
- digit[4][6] = " 8888";
- digit[5][0] = "88888";
- digit[5][1] = "8 ";
- digit[5][2] = "8888 ";
- digit[5][3] = " 8";
- digit[5][4] = " 8";
- digit[5][5] = "8 8";
- digit[5][6] = " 888 ";
- digit[6][0] = " 888 ";
- digit[6][1] = "8 ";
- digit[6][2] = "8 ";
- digit[6][3] = "8888 ";
- digit[6][4] = "8 8";
- digit[6][5] = "8 8";
- digit[6][6] = " 888 ";
- digit[7][0] = "88888";
- digit[7][1] = " 8";
- digit[7][2] = " 8";
- digit[7][3] = " 8 ";
- digit[7][4] = " 8 ";
- digit[7][5] = " 8 ";
- digit[7][6] = " 8 ";
- digit[8][0] = " 888 ";
- digit[8][1] = "8 8";
- digit[8][2] = "8 8";
- digit[8][3] = " 888 ";
- digit[8][4] = "8 8";
- digit[8][5] = "8 8";
- digit[8][6] = " 888 ";
- digit[9][0] = " 888 ";
- digit[9][1] = "8 8";
- digit[9][2] = "8 8";
- digit[9][3] = " 8888";
- digit[9][4] = " 8";
- digit[9][5] = " 8";
- digit[9][6] = " 888 ";
- digit[10][0] = " ";
- digit[10][1] = " ";
- digit[10][2] = " ";
- digit[10][3] = " ";
- digit[10][4] = " ";
- digit[10][5] = " ";
- digit[10][6] = " ";
- digit[11][0] = " ";
- digit[11][1] = " 8 ";
- digit[11][2] = " ";
- digit[11][3] = " ";
- digit[11][4] = " ";
- digit[11][5] = " 8 ";
- digit[11][6] = " ";
- digit[12][0] = " ";
- digit[12][1] = " ";
- digit[12][2] = " 88 ";
- digit[12][3] = " 8";
- digit[12][4] = " 888";
- digit[12][5] = " 8 8";
- digit[12][6] = " 888";
- digit[13][0] = " ";
- digit[13][1] = " ";
- digit[13][2] = " 88 ";
- digit[13][3] = " 8 8";
- digit[13][4] = " 888 ";
- digit[13][5] = " 8 ";
- digit[13][6] = " 8 ";
- digit[14][0] = " ";
- digit[14][1] = " ";
- digit[14][2] = " 8 8 ";
- digit[14][3] = " 8 8 8";
- digit[14][4] = " 8 8 8";
- digit[14][5] = " 8 8 8";
- digit[14][6] = " 8 8 8";
- } // end createDigits
- private static String strTime;
- private static String[][] digit = new String[15][7];
- } // end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement