package package002;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;

public class Demo002旋转时钟 extends JFrame{
TranPanel panel; public static void main(String[] args) { Demo002旋转时钟 frame =
new Demo002旋转时钟(); frame.setVisible(true); } public Demo002旋转时钟() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(300, 5, 1000, 1030);
panel=new TranPanel(); setContentPane(panel); new Thread(panel).start(); }
}

class TranPanel extends JPanel implements Runnable{
int h=11; int min=59; int miao=56; public void paint(Graphics g) {
g.fillOval(500-12, 500-12, 14, 14); dynamicClock(g,h,min,miao); } public void
dynamicClock(Graphics g,int h,int min,int miao) {
drawtime(g,"秒",60,860,6,miao);//画笔 时分秒 循环次数 画的x坐标 旋转角度
drawtime(g,"分",60,740,6,min); drawtime(g,"时",24,620,15,h); } public void
drawtime(Graphics g,String time,int num,int drawx,int angle,int startnum) {
Graphics2D g2 = (Graphics2D)g ; for(int i=0+startnum;i<=num+startnum;i++) {
Image img = new ImageIcon("E:\\"+time+"\\"+i%num+time+".jpg").getImage();
g2.translate(500,485); g2.rotate(Math.toRadians(angle));
g2.translate(-500,-485); g2.translate(drawx,485); g2.drawImage(img,0,0,this) ;
g2.translate(-drawx,-485); } } @Override public void run() { while(true) { try
{ Thread.sleep(1000); miao+=1; if(miao>=60) { miao=0; min+=1; } if(min>=60) {
min=0; h+=1; } if(h>=24) { h=1; }
System.out.println("当前时间:"+h+"时"+min+"分"+miao+"秒"); repaint(); } catch
(InterruptedException e) { e.printStackTrace(); } } }
}

技术
©2019-2020 Toolsou All rights reserved,
数据迁移的套路GO语言flag参数解析x64驱动操作注册表学习QT之Qt::WindowFlags枚举类型详解Java并发编程二:Callable Future乘风破浪会有时,直挂云帆济沧海 展望2019Qt之使用setWindowFlags方法遇到的问题关于setWindowFlags的一点提示List转Map的三种方法攻防世界web simple_js chr() 用法 python3