手机时钟(加了表盘)代码

  1. import java.util.*;
  2. import javax.microedition.lcdui.*;
  3. import javax.microedition.midlet.MIDlet;
  4. public class Exec extends MIDlet {
  5.     private Display display;
  6.     DrawPanel dp = new DrawPanel();
  7.     public Exec() {
  8.         display = Display.getDisplay(this);
  9.     }
  10.     public void startApp() {
  11.         display.setCurrent(dp);
  12.     }
  13.     public void pauseApp() {
  14.     }
  15.     public void destroyApp(boolean unconditional) {
  16.     }
  17. }
  18. class DrawPanel extends Canvas {
  19.     String str = "";
  20.     int xm, ym, xh, yh, xs, ys;
  21.     int lastxs, lastys, lastxm, lastym, lastxh, lastyh;
  22.     public DrawPanel() {
  23.         xm = ym = xh = yh = xs = ys = 0;
  24.     }
  25.     public void paint(Graphics g) {
  26.         g.setColor(255255255);
  27.         g.fillRect(00, getWidth(), getHeight());
  28.         g.setColor(000);
  29.         Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
  30.         calendar.set(Calendar.HOUR_OF_DAY, (calendar.get(Calendar.HOUR_OF_DAY) + 8) % 24);
  31.         int hour = calendar.get(Calendar.HOUR);
  32.         int min = calendar.get(Calendar.MINUTE);
  33.         int se = calendar.get(Calendar.SECOND) + 1;
  34.         xs = (int) (Math.cos(se * 3.14f / 30 - 3.14f / 2) * 45 + 117);
  35.         ys = (int) (Math.sin(se * 3.14f / 30 - 3.14f / 2) * 45 + 93);
  36.         xm = (int) (Math.cos(min * 3.14f / 30 - 3.14f / 2) * 40 + 117);
  37.         ym = (int) (Math.sin(min * 3.14f / 30 - 3.14f / 2) * 40 + 93);
  38.         xh = (int) (Math.cos((hour * 30 + min / 2) * 3.14f / 180 - 3.14f / 2) * 30 + 117);
  39.         yh = (int) (Math.sin((hour * 30 + min / 2) * 3.14f / 180 - 3.14f / 2) * 30 + 93);
  40.         str = hour + " " + ":" + " " + min + " " + ":" + " " + se;
  41.         Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);
  42.         g.setFont(font);
  43.         g.drawArc(54301261260360);
  44.         g.drawString(str, getWidth() / 2 - 32, getHeight() * 2 / 3, Graphics.TOP | Graphics.LEFT);
  45.         g.drawString("9"6189, Graphics.TOP | Graphics.LEFT);
  46.         g.drawString("3"17089, Graphics.TOP | Graphics.LEFT);
  47.         g.drawString("12"11233, Graphics.TOP | Graphics.LEFT);
  48.         g.drawString("6"113140, Graphics.TOP | Graphics.LEFT);
  49.         g.setColor(25500);
  50.         g.drawLine(11793, xs, ys);
  51.         g.setColor(1000255);
  52.         g.drawLine(11793, xm, ym);
  53.         g.drawLine(11792, xh, yh);
  54.         g.drawLine(11693, xh, yh);
  55.         try {
  56.             Thread.sleep(1000);
  57.         } catch (InterruptedException e) {
  58.         }
  59.         repaint();
  60.     }
  61. }
抱歉,我是一个语言模型AI,没有办法直接为您编写代码。不过,以下是一个使用Python语言绘制RTC时钟表盘的示例代码,供您参考: ```python import turtle import math # 设置窗口大小 turtle.setup(800, 800) turtle.title("RTC时钟表盘") # 绘制表盘外框 turtle.penup() turtle.goto(0, -200) turtle.pendown() turtle.circle(200) # 绘制小时刻度 for i in range(12): turtle.penup() turtle.goto(0, 170) turtle.right(i * 30) turtle.pendown() turtle.forward(20) turtle.penup() turtle.goto(0, 150) turtle.write(str(i+1), align="center", font=("Arial", 12, "normal")) turtle.goto(0, 0) # 绘制分钟刻度 for i in range(60): turtle.penup() turtle.goto(0, 190) turtle.right(i * 6) turtle.pendown() if i % 5 == 0: turtle.forward(10) else: turtle.dot(2) turtle.goto(0, 0) # 绘制时针、分针和秒针 hour_hand = turtle.Turtle() minute_hand = turtle.Turtle() second_hand = turtle.Turtle() hour_hand.penup() minute_hand.penup() second_hand.penup() hour_hand.goto(0, 0) minute_hand.goto(0, 0) second_hand.goto(0, 0) hour_hand.right(90) minute_hand.right(90) second_hand.right(90) hour_hand.pensize(5) minute_hand.pensize(3) second_hand.pensize(1) while True: # 获取当前时间 now = turtle.datetime.datetime.now() # 计算时针、分针和秒针的角度 hour_angle = (now.hour % 12) * 30 + now.minute / 2 minute_angle = now.minute * 6 second_angle = now.second * 6 # 旋转时针、分针和秒针 hour_hand.setheading(hour_angle) minute_hand.setheading(minute_angle) second_hand.setheading(second_angle) # 绘制时针、分针和秒针 hour_hand.pendown() hour_hand.forward(60) hour_hand.penup() minute_hand.pendown() minute_hand.forward(90) minute_hand.penup() second_hand.pendown() second_hand.forward(120) second_hand.penup() # 暂停1秒钟 turtle.delay(1000) # 清除时针、分针和秒针 hour_hand.clear() minute_hand.clear() second_hand.clear() turtle.done() ``` 该代码使用turtle库绘制RTC时钟表盘和时针、分针、秒针,并通过获取当前时间来控制时针、分针、秒针的旋转。您可以根据自己的需求进行修改和优化。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值