Advertisement
brilliant_moves

BigTime.java

Aug 3rd, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 5.75 KB | None | 0 0
  1. import java.util.*;     // for GregorianCalendar
  2.  
  3. public class BigTime {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         /**
  8.         *   Program: BigTime.java
  9.         *   Purpose: Command line Digital clock with large scrolling display
  10.         *   Creator: Chris Clarke
  11.         *   Created: 17-18.01.2011
  12.         *   Modified: 19.10.2012 add Thread.sleep(), reposition display
  13.         */
  14.  
  15.         // method call to create digits
  16.         createDigits();
  17.  
  18.         while (true) {
  19.             strTime = "";
  20.             // clear screen
  21.             for (int i = 0; i < 25; i++) {
  22.                 // slow down scrolling
  23.                 slowItDown(40);
  24.                 System.out.println();
  25.             } // end for
  26.  
  27.             // create instance of calendar
  28.             GregorianCalendar now = new GregorianCalendar();
  29.             int hour = now.get(Calendar.HOUR);
  30.             int amPm = now.get(Calendar.AM_PM);
  31.             int minute = now.get(Calendar.MINUTE);
  32.  
  33.             if (hour == 0) {
  34.                 hour = 12;
  35.             } // end if
  36.             // "01", "02" etc instead of "1", "2" etc
  37.             if (hour < 10) {
  38.                 strTime += " "; // add a space
  39.                 // or strTime += "0"; // or add a zero
  40.             } // end if
  41.             strTime += hour;
  42.                 strTime += ":";
  43.             // "00", "01", "02" etc instead of "0", "1", "2"
  44.             if (minute<10) {
  45.                 strTime += "0";
  46.             } // end if
  47.             strTime += minute;
  48.  
  49.             // method call to display large characters
  50.             displayLetters( amPm);
  51.  
  52.             int newMinute;
  53.             // loop until newMinute changes
  54.             do {
  55.                 GregorianCalendar later = new GregorianCalendar();
  56.                 // create new instance of calendar
  57.                 newMinute = later.get(Calendar.MINUTE);
  58.                 // get current minute
  59.             } while (newMinute == minute);
  60.         } // end while
  61.     } // end main
  62.  
  63.     public static void slowItDown(int amount) {
  64.         try {
  65.             Thread.sleep(amount);
  66.         } catch (Exception x) {
  67.             System.out.println("Caught Exception! " + x.getMessage());
  68.         } // end try...catch
  69.     } // end slowItDown
  70.  
  71.     public static void displayLetters( int amPm) {
  72.         String ch = "";
  73.         int digitNum = 0;
  74.         for (int row = 0; row < 7; row++) {
  75.             // slow down scrolling of text
  76.             slowItDown(40);
  77.  
  78.             System.out.print("\t\t");
  79.             for (int i = 0; i < 5; i++) {
  80.                 // separate into 5 Strings
  81.                 ch = strTime.substring(i, i+1);
  82.                 if (i == 2) {
  83.                     // colon
  84.                     digitNum = 11;
  85.                 } else {
  86.                     if (ch.equals(" " )) {
  87.                         // space
  88.                         digitNum = 10;
  89.                     } else {
  90.                         // number 0-9
  91.                         digitNum = Integer.parseInt(ch);
  92.                     } // end if
  93.                 } // end if
  94.                 System.out.print(digit[digitNum][row]);
  95.                 // add space
  96.                 System.out.print(" ");
  97.             } // end for i
  98.             if (amPm == 0) {
  99.                 // "a" for "am"
  100.                 digitNum = 12;
  101.             } else {
  102.                 // "p" for "pm"
  103.                 digitNum = 13;
  104.             } // end if
  105.             System.out.print(digit[digitNum][row]);
  106.             System.out.println(digit[14][row]); // "m" for am/pm
  107.         } // end for row
  108.         for (int j = 0; j < 9; j++) { // move text up 9 rows
  109.             // slow down scrolling of text
  110.             slowItDown(40);
  111.             System.out.println();   // new line
  112.         } // end for j
  113.     } // end displayLargeCharacters
  114.  
  115.     public static void createDigits() {
  116.  
  117.         digit[0][0] = " 888 ";
  118.         digit[0][1] = "8   8";
  119.         digit[0][2] = "8  88";
  120.         digit[0][3] = "8 8 8";
  121.         digit[0][4] = "88  8";
  122.         digit[0][5] = "8   8";
  123.         digit[0][6] = " 888 ";
  124.  
  125.         digit[1][0] = "   8 ";
  126.         digit[1][1] = "  88 ";
  127.         digit[1][2] = "   8 ";
  128.         digit[1][3] = "   8 ";
  129.         digit[1][4] = "   8 ";
  130.         digit[1][5] = "   8 ";
  131.         digit[1][6] = "  888";
  132.  
  133.         digit[2][0] = " 888 ";
  134.         digit[2][1] = "8   8";
  135.         digit[2][2] = "    8";
  136.         digit[2][3] = "   8 ";
  137.         digit[2][4] = "  8  ";
  138.         digit[2][5] = " 8   ";
  139.         digit[2][6] = "88888";
  140.  
  141.         digit[3][0] = " 888 ";
  142.         digit[3][1] = "8   8";
  143.         digit[3][2] = "    8";
  144.         digit[3][3] = "  888";
  145.         digit[3][4] = "    8";
  146.         digit[3][5] = "8   8";
  147.         digit[3][6] = " 888 ";
  148.  
  149.         digit[4][0] = "   8 ";
  150.         digit[4][1] = "  88 ";
  151.         digit[4][2] = " 8 8 ";
  152.         digit[4][3] = "8  8 ";
  153.         digit[4][4] = "88888";
  154.         digit[4][5] = "   8 ";
  155.         digit[4][6] = " 8888";
  156.  
  157.         digit[5][0] = "88888";
  158.         digit[5][1] = "8    ";
  159.         digit[5][2] = "8888 ";
  160.         digit[5][3] = "    8";
  161.         digit[5][4] = "    8";
  162.         digit[5][5] = "8   8";
  163.         digit[5][6] = " 888 ";
  164.  
  165.         digit[6][0] = " 888 ";
  166.         digit[6][1] = "8    ";
  167.         digit[6][2] = "8    ";
  168.         digit[6][3] = "8888 ";
  169.         digit[6][4] = "8   8";
  170.         digit[6][5] = "8   8";
  171.         digit[6][6] = " 888 ";
  172.  
  173.         digit[7][0] = "88888";
  174.         digit[7][1] = "    8";
  175.         digit[7][2] = "    8";
  176.         digit[7][3] = "   8 ";
  177.         digit[7][4] = "  8  ";
  178.         digit[7][5] = "  8  ";
  179.         digit[7][6] = "  8  ";
  180.  
  181.         digit[8][0] = " 888 ";
  182.         digit[8][1] = "8   8";
  183.         digit[8][2] = "8   8";
  184.         digit[8][3] = " 888 ";
  185.         digit[8][4] = "8   8";
  186.         digit[8][5] = "8   8";
  187.         digit[8][6] = " 888 ";
  188.  
  189.         digit[9][0] = " 888 ";
  190.         digit[9][1] = "8   8";
  191.         digit[9][2] = "8   8";
  192.         digit[9][3] = " 8888";
  193.         digit[9][4] = "    8";
  194.         digit[9][5] = "    8";
  195.         digit[9][6] = " 888 ";
  196.  
  197.         digit[10][0] = "     ";
  198.         digit[10][1] = "     ";
  199.         digit[10][2] = "     ";
  200.         digit[10][3] = "     ";
  201.         digit[10][4] = "     ";
  202.         digit[10][5] = "     ";
  203.         digit[10][6] = "     ";
  204.  
  205.         digit[11][0] = "   ";
  206.         digit[11][1] = " 8 ";
  207.         digit[11][2] = "   ";
  208.         digit[11][3] = "   ";
  209.         digit[11][4] = "   ";
  210.         digit[11][5] = " 8 ";
  211.         digit[11][6] = "   ";
  212.  
  213.         digit[12][0] = "     ";
  214.         digit[12][1] = "     ";
  215.         digit[12][2] = "  88 ";
  216.         digit[12][3] = "    8";
  217.         digit[12][4] = "  888";
  218.         digit[12][5] = " 8  8";
  219.         digit[12][6] = "  888";
  220.  
  221.         digit[13][0] = "     ";
  222.         digit[13][1] = "     ";
  223.         digit[13][2] = "  88 ";
  224.         digit[13][3] = " 8  8";
  225.         digit[13][4] = " 888 ";
  226.         digit[13][5] = " 8   ";
  227.         digit[13][6] = " 8   ";
  228.  
  229.         digit[14][0] = "      ";
  230.         digit[14][1] = "      ";
  231.         digit[14][2] = "  8 8 ";
  232.         digit[14][3] = " 8 8 8";
  233.         digit[14][4] = " 8 8 8";
  234.         digit[14][5] = " 8 8 8";
  235.         digit[14][6] = " 8 8 8";
  236.  
  237.     } // end createDigits
  238.  
  239.     private static String strTime;
  240.     private static String[][] digit = new String[15][7];
  241.  
  242. } // end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement