大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全家桶1年46,售后保障稳定
Java液晶数字字体显示当前时间
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author zdy
* @version 2019年3月11日16:03:12
*/
public class PrintDate {
private final static String[][] parr = {
{" ","-","-"," "," ","-","-"," "," "," ","-","-"," "," ","-","-"," "},
{"|"," "," ","|","|"," "," ","|",".","|"," "," ","|","|"," "," ","|"},
{" ","-","-"," "," ","-","-"," "," "," ","-","-"," "," ","-","-"," "},
{"|"," "," ","|","|"," "," ","|",".","|"," "," ","|","|"," "," ","|"},
{" ","-","-"," "," ","-","-"," "," "," ","-","-"," "," ","-","-"," "}};
public static void main(String[] args) throws InterruptedException {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
while(true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
print(parr);
}
}
});
t.start();
t.join(0);
}
private static void print(String[][] arr) {
Map<Integer,List<Integer>> m = getDateArr();
for (int i = 0; i < arr.length; i++) {
List<Integer> indexs = m.get(i);
for (int l = 0; l < arr[i].length; l++) {
boolean flag = false;
for (Integer index : indexs) {
if(index == l) {
flag = true;
break;
}
}
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(!flag) {
System.out.print(arr[i][l]);
} else {
System.err.print(arr[i][l]);
}
}
System.out.println();
}
}
private static Map<Integer,List<Integer>> getDateArr(){
Map<Integer,List<Integer>> m = new HashMap<>();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
String currentTime = sdf.format(new Date());
System.out.println(currentTime);
String[] time = currentTime.split(":");
String[] hour = time[0].split("");
for (int i = 0; i < hour.length; i++) {
Map<Integer, List<Integer>> tmp = getDateArrD(Integer.valueOf(hour[i]), i,0);
if(!tmp.isEmpty()) {
tmp.keySet().forEach(key -> {
List<Integer> list = m.get(key);
if(list ==null || list.size() <= 0) {
m.put(key, tmp.get(key));
} else {
list.addAll(tmp.get(key));
m.put(key, list);
}
});
}
}
String[] minute = time[1].split("");
for (int i = 0; i < minute.length; i++) {
Map<Integer, List<Integer>> tmp = getDateArrD(Integer.valueOf(minute[i]), i+2,1);
if(!tmp.isEmpty()) {
tmp.keySet().forEach(key -> {
List<Integer> list = m.get(key);
if(list ==null || list.size() <= 0) {
m.put(key, tmp.get(key));
} else {
list.addAll(tmp.get(key));
m.put(key, list);
}
});
}
}
return m;
}
private static Map<Integer,List<Integer>> getDateArrD(int num,int index,int n){
Map<Integer,List<Integer>> m = new HashMap<>();
List<Integer> n1 = null;
switch(num) {
default:
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(0, n1);
n1 = new ArrayList<>();
n1.add(0+index*4+n);
n1.add(3+index*4+n);
m.put(1, n1);
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(3+index*4+n);
m.put(3, n1);
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(4, n1);
return m;
case 1:
n1 = new ArrayList<>();
n1.add(3+index*4+n);
m.put(1, n1);
n1 = new ArrayList<>();
n1.add(3+index*4+n);
m.put(3, n1);
return m;
case 2:
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(0, n1);
n1 = new ArrayList<>();
n1.add(4+index*4+n);
m.put(1, n1);
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(2, n1);
n1 = new ArrayList<>();
n1.add(0+index*4+n);
m.put(3, n1);
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(4, n1);
return m;
case 3:
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(0, n1);
n1 = new ArrayList<>();
n1.add(3+index*4+n);
m.put(1, n1);
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(2, n1);
n1 = new ArrayList<>();
n1.add(3+index*4+n);
m.put(3, n1);
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(4, n1);
return m;
case 4:
n1 = new ArrayList<>();
n1.add(0+index*4+n);
n1.add(3+index*4+n);
m.put(1, n1);
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(2, n1);
n1 = new ArrayList<>();
n1.add(3+index*4+n);
m.put(3, n1);
return m;
case 5:
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(0, n1);
n1 = new ArrayList<>();
n1.add(0+index*4+n);
m.put(1, n1);
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(2, n1);
n1 = new ArrayList<>();
n1.add(3+index*4+n);
m.put(3, n1);
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(4, n1);
return m;
case 6:
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(0, n1);
n1 = new ArrayList<>();
n1.add(0+index*4+n);
m.put(1, n1);
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(2, n1);
n1 = new ArrayList<>();
n1.add(0+index*4+n);
n1.add(3+index*4+n);
m.put(3, n1);
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(4, n1);
return m;
case 7:
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(0, n1);
n1 = new ArrayList<>();
n1.add(3+index*4+n);
m.put(1, n1);
n1 = new ArrayList<>();
n1.add(3+index*4+n);
m.put(3, n1);
return m;
case 8:
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(0, n1);
n1 = new ArrayList<>();
n1.add(0+index*4+n);
n1.add(3+index*4+n);
m.put(1, n1);
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(2, n1);
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(3+index*4+n);
m.put(3, n1);
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(4, n1);
return m;
case 9:
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(0, n1);
n1 = new ArrayList<>();
n1.add(0+index*4+n);
n1.add(3+index*4+n);
m.put(1, n1);
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(2, n1);
n1 = new ArrayList<>();
n1.add(3+index*4+n);
m.put(3, n1);
n1 = new ArrayList<>();
n1.add(1+index*4+n);
n1.add(2+index*4+n);
m.put(4, n1);
return m;
}
}
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/223014.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...