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实现液晶数字字体显示当前时间


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

相关文章

摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠...
摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠...
今天犯了个错:“接口变动,伤筋动骨,除非你确定只有你一个...
Writer :BYSocket(泥沙砖瓦浆木匠)微 博:BYSocket豆 瓣:...
本文目录 线程与多线程 线程的运行与创建 线程的状态 1 线程...