java实现液晶数字字体显示当前时间

前端之家收集整理的这篇文章主要介绍了java实现液晶数字字体显示当前时间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例为大家分享了java实现液晶数字字体显示当前时间的具体代码,供大家参考,具体内容如下

java实现液晶数字字体显示当前时间


import java.text.SimpleDateFormat;
import java.util.Date; 

public class TestTime {
  public static String[][] num0 = new String[][] { { " ","-"," " },{ "|"," ","|" },{ " "," " } };
  public static String[][] num1 = new String[][] { { " "," " } };
  public static String[][] num2 = new String[][] { { " "," " } };
  public static String[][] num3 = new String[][] { { " "," " } };
  public static String[][] num4 = new String[][] { { " "," " } };
  public static String[][] num5 = new String[][] { { " "," " } };
  public static String[][] num6 = new String[][] { { " "," " } };
  public static String[][] num7 = new String[][] { { " "," " } };
  public static String[][] num8 = new String[][] { { " "," " } };
  public static String[][] num9 = new String[][] { { " "," " } }; 

  public static String[][] option = new String[][] { { " ","●"," " } };
  public static String[][][] numAll = new String[][][] { num0,num1,num2,num3,num4,num5,num6,num7,num8,num9 };
  public static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); 

  public static void main(String[] args) {
    print();
  } 

  public static void print() {
    String[][][] newStr = getDateArray();
    for (int i = 0; i < 5; i++) {
      for (int k = 0; k < newStr.length; k++) {
        for (int j = 0; j < 3; j++) {
          System.out.print(newStr[k][i][j]);
        }
        System.out.print(" ");
      }
      System.out.println();
    }
  } 

  public static String[][][] getDateArray() {
    String[][][] dateArray = new String[5][][];
    String dateStr = sdf.format(new Date());
    char[] dateChars = dateStr.tocharArray();
    for (int i = 0; i < dateChars.length; i++) {
      switch (dateChars[i]) {
      case ':':
        dateArray[i] = option;
        break;
      default:
        dateArray[i] = numAll[Integer.valueOf(String.valueOf(dateChars[i]))];
        break;
      }
    } 

    return dateArray;
  }
}

输出结果:

java实现液晶数字字体显示当前时间


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

猜你在找的Java相关文章