搜索热词
本文实例为大家分享了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;
}
}
输出结果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
总结
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。