Java实现LED方式显示时间

Heavenka 2010-12-13 05:13:16
本人最近做java的课程设计,要求:
编写一个时钟(LED方式)程序,要求:
(1)在屏幕上用文字显示日期(年、月、日、星期)与时间。
(2)时间显示要求能动态显示时、分、秒。

本人只知道用文本方式显示动态时间,希望高手讲解实现方式,我想知道的是实现原理,而不仅仅是程序代码。从网上下载了个电子钟程序,原程序中包含很多16进制数,不知道什么原理实现的。
...全文
506 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Heavenka 2010-12-14
  • 打赏
  • 举报
回复
//Fu Bin MSN:yonghe169@163.com
//Finish CodeFans.net
public class Font /* 字型*/ {
public static int font[]={
0x00,0x00,0x00,0x00,0x00, /*Spacebar*/
0x00,0x00,0x4F,0x00,0x00, /*!*/
0x00,0x07,0x00,0x07,0x00, /*"*/
0x14,0x7F,0x14,0x7F,0x14, /*#*/
0x24,0x2A,0x7F,0x2A,0x12, /*$*/
0x23,0x13,0x08,0x64,0x62, /*%*/
0x36,0x49,0x55,0x22,0x50, /*&*/
0x00,0x05,0x03,0x00,0x00, /*'*/
0x00,0x1C,0x22,0x41,0x00, /*(*/
0x00,0x41,0x22,0x1C,0x00, /*)*/
0x14,0x08,0x3E,0x08,0x14, /*Star*/
0x08,0x08,0x3E,0x08,0x08, /*+*/
0x00,0x50,0x30,0x00,0x00, /*,*/
0x08,0x08,0x08,0x08,0x08, /*-*/
0x00,0x60,0x60,0x00,0x00, /*.*/
0x20,0x10,0x08,0x04,0x02, /*Slash*/
0x3E,0x51,0x49,0x45,0x3E, /*0*/
0x00,0x42,0x7F,0x40,0x00, /*1*/
0x42,0x61,0x51,0x49,0x46, /*2*/
0x21,0x41,0x45,0x4B,0x31, /*3*/
0x18,0x14,0x12,0x7F,0x10, /*4*/
0x27,0x45,0x45,0x45,0x39, /*5*/
0x3C,0x4A,0x49,0x49,0x30, /*6*/
0x01,0x71,0x09,0x05,0x03, /*7*/
0x36,0x49,0x49,0x49,0x36, /*8*/
0x06,0x49,0x49,0x29,0x1E, /*9*/
0x00,0x36,0x36,0x00,0x00, /*:*/
0x00,0x56,0x36,0x00,0x00, /*;*/
0x08,0x14,0x22,0x41,0x00, /*<*/
0x14,0x14,0x14,0x14,0x14, /*=*/
0x00,0x41,0x22,0x14,0x08, /*>*/
0x02,0x01,0x51,0x09,0x06, /*?*/
0x32,0x49,0x79,0x41,0x3E, /*@*/
0x7E,0x11,0x11,0x11,0x7E, /*A*/
0x7F,0x49,0x49,0x49,0x36, /*B*/
0x3E,0x41,0x41,0x41,0x22, /*C*/
0x7F,0x41,0x41,0x22,0x1C, /*D*/
0x7F,0x49,0x49,0x49,0x41, /*E*/
0x7F,0x09,0x09,0x09,0x01, /*F*/
0x3E,0x41,0x49,0x49,0x7A, /*G*/
0x7F,0x08,0x08,0x08,0x7F, /*H*/
0x00,0x41,0x7F,0x41,0x00, /*I*/
0x20,0x40,0x41,0x3F,0x01, /*J*/
0x7F,0x08,0x14,0x22,0x41, /*K*/
0x7F,0x40,0x40,0x40,0x40, /*L*/
0x7F,0x02,0x0C,0x02,0x7F, /*M*/
0x7F,0x04,0x08,0x10,0x7F, /*N*/
0x3E,0x41,0x41,0x41,0x3E, /*O*/
0x7F,0x09,0x09,0x09,0x06, /*P*/
0x3E,0x41,0x51,0x21,0x5E, /*Q*/
0x7F,0x09,0x19,0x29,0x46, /*R*/
0x46,0x49,0x49,0x49,0x31, /*S*/
0x01,0x01,0x7F,0x01,0x01, /*T*/
0x3F,0x40,0x40,0x40,0x3F, /*U*/
0x1F,0x20,0x40,0x20,0x1F, /*V*/
0x3F,0x40,0x38,0x40,0x3F, /*W*/
0x63,0x14,0x08,0x14,0x63, /*X*/
0x07,0x08,0x70,0x08,0x07, /*Y*/
0x61,0x51,0x49,0x45,0x43, /*Z*/
0x00,0x7F,0x41,0x41,0x00, /*[*/
0x18,0x24,0x7E,0x24,0x10, /**/
0x00,0x41,0x41,0x7F,0x00, /*]*/
0x04,0x02,0x01,0x02,0x04, /*^*/
0x40,0x40,0x40,0x40,0x40, /*_*/
0x00,0x01,0x02,0x00,0x00, /*'*/
0x20,0x54,0x54,0x54,0x78, /*a*/
0x7F,0x48,0x44,0x44,0x38, /*b*/
0x38,0x44,0x44,0x44,0x20, /*c*/
0x38,0x44,0x44,0x48,0x7F, /*d*/
0x38,0x54,0x54,0x54,0x18, /*e*/
0x08,0x7E,0x09,0x01,0x02, /*f*/
0x08,0x54,0x54,0x54,0x3C, /*g*/
0x7F,0x08,0x04,0x04,0x78, /*h*/
0x00,0x44,0x7D,0x40,0x00, /*i*/
0x20,0x40,0x44,0x3D,0x00, /*j*/
0x7F,0x10,0x28,0x44,0x00, /*k*/
0x00,0x41,0x7F,0x40,0x00, /*l*/
0x7C,0x04,0x18,0x04,0x78, /*m*/
0x7C,0x08,0x04,0x04,0x78, /*n*/
0x38,0x44,0x44,0x44,0x38, /*o*/
0x7C,0x14,0x14,0x14,0x08, /*p*/
0x08,0x14,0x14,0x14,0x7C, /*q*/
0x7C,0x08,0x04,0x04,0x08, /*r*/
0x48,0x54,0x54,0x54,0x20, /*s*/
0x04,0x3F,0x44,0x40,0x20, /*t*/
0x3C,0x40,0x40,0x20,0x7C, /*u*/
0x1C,0x20,0x40,0x20,0x1C, /*v*/
0x3C,0x40,0x30,0x40,0x3C, /*w*/
0x44,0x28,0x10,0x28,0x44, /*x*/
0x0C,0x50,0x50,0x50,0x3C, /*y*/
0x44,0x64,0x54,0x4C,0x44 /*z*/
};

public static boolean fontArray[][] = new boolean[font.length][8];

static{
for (int i=0;i<font.length;i++){
for (int j=0;j<8;j++){
fontArray[i][j] = ((font[i]&(1<<j)) == 0)?false:true;
}
}
}
}
Heavenka 2010-12-14
  • 打赏
  • 举报
回复
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;



public class LedClock{
static LedClockWindow ledClockWindow;
public static void main(String arg[]){
ledClockWindow = new LedClockWindow();
}
}



Heavenka 2010-12-14
  • 打赏
  • 举报
回复
谢谢楼上两个 你们说的都没达到要求 我发个程序给你们 不过看不懂
eswn 2010-12-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 bao110908 的回复:]

给你个 JavaScript 版的吧,我原来写的:



led.js

JScript code
var Led = function(options) {
this.options = {
'count' : 1,
'color' : '#ff0000',
'dark' : '#ffffff',
'height' : 100,……
[/Quote]
+1
  • 打赏
  • 举报
回复
给你个 JavaScript 版的吧,我原来写的:



led.js

var Led = function(options) {
this.options = {
'count' : 1,
'color' : '#ff0000',
'dark' : '#ffffff',
'height' : 100,
'width' : 50,
'parent' : 'leds',
'spacing' : 10,
'weight' : 10,
'prefix' : 'ledNum_'
};
Object.extend(this.options, options || {});
this.options.prefix = this.options.parent + '_' + this.options.prefix;
this.allLeds = Led.getAllNum();
this.init();
}

Led.prototype = {
init : function() {
var leds = $(this.options.parent);
for(var i = this.options.count - 1; i >= 0; i--) {
var led = document.createElement('div');
led.id = this.options.prefix + i;
with(led.style) {
padding = this.options.spacing + 'px';
}
MyUtil.addCssFloat(led, 'left');
var _a = document.createElement('div');
var attachWeight = this.options.weight % 2 == 0;
var semiWeight = Math.floor(this.options.weight / 2);
with(_a.style) {
width = this.options.width + 'px';
height = this.options.height / 2 + 'px';
borderTop =
borderRight =
borderLeft = this.options.weight + 'px ' + 'solid ' + this.options.color;
borderBottom = (attachWeight ? semiWeight : semiWeight + 1) + 'px ' + 'solid ' + this.options.dark;
overflow = 'hidden';
}
var _b = document.createElement('div');
with(_b.style) {
width = this.options.width + 'px';
height = this.options.height / 2 + 'px';
borderRight =
borderLeft =
borderBottom = this.options.weight + 'px ' + 'solid ' + this.options.color;
borderTop = semiWeight + 'px ' + 'solid ' + this.options.dark;
overflow = 'hidden';
}
_a.innerHTML = _b.innerHTML = ' ';
led.appendChild(_a);
led.appendChild(_b);
leds.appendChild(led);
}
},

showNumber : function(num) {
var digits = Led.getDigits(num, this.options.count);
for(var i = 0; i < this.options.count; i++) {
var led = $(this.options.prefix + i);
this.show(led, this.allLeds[digits[i]]);
}
},

show : function(d, led) {
var tmp = d.childNodes;
var ls = [];
for(var i = 0, n = 0; i < tmp.length; i++) {
if(tmp[i].tagName == 'DIV') {
ls[n++] = tmp[i];
}
}
with(ls[0].style) {
borderTopColor = led[0] ? this.options.color : this.options.dark;
borderRightColor = led[1] ? this.options.color : this.options.dark;
borderBottomColor = led[6] ? this.options.color : this.options.dark;
borderLeftColor = led[5] ? this.options.color : this.options.dark;
}
with(ls[1].style) {
borderTopColor = led[6] ? this.options.color : this.options.dark;
borderRightColor = led[2] ? this.options.color : this.options.dark;
borderBottomColor = led[3] ? this.options.color : this.options.dark;
borderLeftColor = led[4] ? this.options.color : this.options.dark;
}
}
}

Led.getAllNum = function() {
var getLogic = function(num) {
var a = (num & 8) >>> 3 == 1;
var b = (num & 4) >>> 2 == 1;
var c = (num & 2) >>> 1 == 1;
var d = (num & 1) == 1;
var led = [];
led[0] = a | (!a & c) |(!a & !b & !c & !d) | (!a & b & !c & d);
led[1] = a | (!a & !b) | (!a & b & c & d) | (!a & b & !c & !d);
led[2] = a | b | !c | d;
led[3] = a | (!a & !b & c) | (!a & !b & !c & !d) | (!a & b & c & !d) |
(!a & b & !c & d);
led[4] = (!a & c & !d) | (!b & !c & !d);
led[5] = a | (!a & !b & !c & !d) | (!a & b & !d) | (!a & b & !c & d);
led[6] = a | (!a & !b & c) | (!a & b & !c) | (!a & b & c & !d);
return led;
}
var leds = [];
for(var i = 0; i < 10; i++) {
leds[i] = getLogic(i);
}
return leds;
}

Led.getDigits = function(num, count) {
num = num || 0;
count = count || 1;
var digits = [];
for(var i = 0; i < count; i++) {
digits[i] = num % 10;
num = Math.floor(num / 10);
}
return digits;
}



led.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<script type="text/javascript" src="led.js"></script>

<script type="text/javascript">
$ = function(id) {
return (typeof id == 'string') ? document.getElementById(id) : id;
}

/**
* Prototype JavaScript Utilitity
*/
Object.extend = function(destination, source) {
for (var property in source) {
if(source[property] instanceof Object) {
this.extend(destination[property], source[property]);
} else {
destination[property] = source[property];
}
}
return destination;
};

var MyUtil = {
addCssFloat : function(element, align) {
if(typeof element.style.styleFloat != 'undefined') {
element.style.styleFloat = align;
} else {
element.style.cssFloat = align;
}
}
}

window.onload = function() {
var width = 12;
var height = 24;
var weight = 8;
var dark = '#efefef';
var color = '#000000';

var year = new Led({
parent: 'year',
count: 4,
width: width,
height: height,
weight: weight,
spacing: 2,
dark: dark,
color: color
});
var month = new Led({
parent: 'month',
count: 2,
width: width,
height: height,
weight: weight,
spacing: 2,
dark: dark,
color: color
});
var day = new Led({
parent: 'day',
count: 2,
width: width,
height: height,
weight: weight,
spacing: 2,
dark: dark,
color: color
});
var hour = new Led({
parent: 'hour',
count: 2,
width: width,
height: height,
weight: weight,
spacing: 2,
dark: dark,
color: color
});
var minute = new Led({
parent: 'minute',
count: 2,
width: width,
height: height,
weight: weight,
spacing: 2,
dark: dark,
color: color
});
var second = new Led({
parent: 'second',
count: 2,
width: width,
height: height,
weight: weight,
spacing: 2,
dark: dark,
color: color
});
var d = new Date();
var _year = d.getYear();
year.showNumber((_year < 1900 ? (1900 + _year) : _year));
month.showNumber(d.getMonth() + 1);
day.showNumber(d.getDate());
hour.showNumber(d.getHours());
minute.showNumber(d.getMinutes());
second.showNumber(d.getSeconds());


var id = setInterval(function() {
var d = new Date();
var _second = d.getSeconds();
second.showNumber(_second);
if(_second != 0) {
return;
}

var _minute = d.getMinutes();
minute.showNumber(_minute);
if(_minute != 0) {
return;
}

var _hour = d.getHours();
hour.showNumber(_hour);
if(_hour != 0) {
return;
}

var _date = d.getDate();
day.showNumber(_date);
if(_date != 1) {
return;
}

var _month = d.getMonth();
month.showNumber(_month + 1);
if(_month != 0) {
return;
}

year.showNumber((_year < 1900 ? (1900 + _year) : _year));
}, 1000);
}
</script>

<style>
div.t {
float: left;
}
span.sepa {
font-size: 32pt;
font-weight: bold;
color: #000000;
}
</style>
</head>

<body>
<div id="time">
<div class="t" id="year"></div>
<div class="t"><span class="sepa">-</span></div>
<div class="t" id="month"></div>
<div class="t"><span class="sepa">-</span></div>
<div class="t" id="day"></div>
<div class="t"><span class="sepa"> </span></div>
<div class="t" id="hour"></div>
<div class="t"><span class="sepa">:</span></div>
<div class="t" id="minute"></div>
<div class="t"><span class="sepa">:</span></div>
<div class="t" id="second"></div>
</div>
</body>
</html>
Jlins 2010-12-13
  • 打赏
  • 举报
回复
需要通过 图形界面画出来了...

用图形界面封装下 1~9 数字吧
Heavenka 2010-12-13
  • 打赏
  • 举报
回复
帖子 发得太快了,我还是顶上去。
Heavenka 2010-12-13
  • 打赏
  • 举报
回复
编写一个时钟([color=#FF0000]LED方式)程序,要求:
(1)在屏幕上用文字显示日期(年、月、日、星期)与时间。
(2)时间显示要求能动态显示时、分、秒。[/color]

颜色没弄好 重要的就是LED显示
Jlins 2010-12-13
  • 打赏
  • 举报
回复
本人只知道用文本方式显示动态时间

上面的要求就是 文本数据显示 动态刷新吧.没别的吧?

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧