数字时钟
来源:互联网 发布:c语言指针偏移 编辑:程序博客网 时间:2024/04/30 03:28
import java.util.Calendar;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
public class Exec extends MIDlet {
private Display display;
public Exec() {
display = Display.getDisplay(this);
}
public void startApp() {
display.setCurrent(new DrawPanel());
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
class DrawPanel extends Canvas {
String time = "";
Thread thread = new Thread(new ActionThread());
public DrawPanel() {
thread.start();
}
public void paint(Graphics g) {
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0, 0, 0);
Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD,
Font.SIZE_LARGE);
g.setFont(font);
int fontWidth = font.stringWidth(time);
int fontHeight = font.getHeight();
g.drawString(time, getWidth() / 2 - fontWidth / 2, getHeight() / 2
- fontHeight / 2, Graphics.TOP | Graphics.LEFT);
}
class ActionThread implements Runnable {
final int beijingZone = 8;
public void run() {
while (true) {
Calendar rightNow = Calendar.getInstance();
int hour = rightNow.get(Calendar.HOUR_OF_DAY) + beijingZone;
int minute = rightNow.get(Calendar.MINUTE);
int second = rightNow.get(Calendar.SECOND);
time = "";
String sh = String.valueOf(hour);
if (sh.length() == 1)
time = time + "0";
time = time + sh + ":";
sh = String.valueOf(minute);
if (sh.length() == 1)
time = time + "0";
time = time + sh + ":";
sh = String.valueOf(second);
if (sh.length() == 1)
time = time + "0";
time = time + sh;
repaint();
try {
Thread.sleep(100);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
}
}
- 数字时钟
- 数字时钟
- 数字时钟
- 数字时钟
- 数字时钟
- 数字时钟
- 数字时钟
- 数字时钟
- 数字时钟
- 数字时钟
- 数字时钟的源代码
- 数字时钟(代码)
- java数字时钟
- js数字时钟
- 数字时钟语音温度计
- 数字时钟语音温度计
- 单片机数字时钟
- 数字时钟系统
- 动态规划算法剖析
- tomcat6.0中配置JNDI的DBCP连接及maxIdle ,MaxActive,maxWait介绍
- OCX控件注册相关(检查是否注册,注册,反注册)
- 时钟
- IT从业人员必看的10大论坛
- 数字时钟
- 输入输出
- Effective C#之17:Minimize Boxing and Unboxing.
- Tomcat6的配置
- ASP.NET实现文件下载(多种方法,而且都是比较常用的)
- 开启博客!
- 装饰模式小例
- 网站设计知识css+div和table+css的比较
- 获取GridView隐藏列值