- import java.util.Calendar;
- import java.util.TimeZone;
- import javax.microedition.lcdui.*;
- import javax.microedition.midlet.MIDlet;
- public class Exec extends MIDlet {
- private Display display;
- DrawPanel dp = new DrawPanel();
- public Exec() {
- display = Display.getDisplay(this);
- }
- public void startApp() {
- display.setCurrent(dp);
- }
- public void pauseApp() {
- }
- public void destroyApp(boolean unconditional) {
- }
- }
- class DrawPanel extends Canvas {
- String str = "";
- public DrawPanel() {
- }
- public void paint(Graphics g) {
- g.setColor(255, 255, 255);
- g.fillRect(0, 0, getWidth(), getHeight());
- g.setColor(0, 0, 0);
- Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
- calendar.set(Calendar.HOUR_OF_DAY, (calendar.get(Calendar.HOUR_OF_DAY) + 8) % 24);
- int hour = calendar.get(Calendar.HOUR);
- int min = calendar.get(Calendar.MINUTE);
- int se = calendar.get(Calendar.SECOND)+1;
- str = hour + " " + ":" + " " + min + " " + ":" + " " + se;
- Font font = Font.getFont(Font.FACE_SYSTEM,
- Font.STYLE_BOLD,
- Font.SIZE_LARGE);
- g.setFont(font);
- int fontWidth = font.stringWidth(str);
- int fontHeight = font.getHeight();
- g.drawString(str, getWidth() / 2 - fontWidth / 2,
- getHeight() / 2 - fontHeight / 2, Graphics.TOP |
- Graphics.LEFT);
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- }
- repaint();
- }
- }
手机数字时钟动态显示
最新推荐文章于 2021-05-26 22:37:59 发布