Java写的创意时钟,纯属好玩,没任何实用价值的说~

先上图吧,有个图比较好解释:)

绿色的圈代表秒,蓝色代表分,品红代表小时
分别以当前的秒所占一分钟的比率,当前的分所占一小时的比率,以及当前的小时所占1天的比率画出弧度~
思路相当简单,不过实现起来还是比较好玩的:)
稍稍修改了一下,现在应该符合常识了
编译好的jar文件在这里下载
http://cid-d94239a09a81fece.skydrive.live.com/self.aspx/.Public/aa.jar
代码如下:

import javax.swing.; import java.util.; import java.awt.; public class ClockPanel { /* * @param args / JFrame frame; Canvas ab; Clock kk; int hh, mm, ss; Calendar cal = null; ClockPanel() { frame = new JFrame("Clock"); frame.setBackground(Color.white); ab = new Canvas(); ab.setSize(400, 400); ab.setBackground(Color.red); frame.setSize(400, 400); frame.add(ab); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); kk = new Clock(this); begin(); } /* * 画图函数,就是很简单的用Calendar类获得当前时间,然后弧形 / void draw() { Graphics g = ab.getGraphics(); g.setColor(Color.red); g.fillRect(0, 0, 400, 400); g.setColor(Color.green); cal = Calendar.getInstance(); hh = cal.get(Calendar.HOUR_OF_DAY); mm = cal.get(Calendar.MINUTE); ss = cal.get(Calendar.SECOND); g.drawString("Nowtime:" + hh + ":" + mm + ":" + ss, 40, 60); int ars = 6 * ss; int arm = 6 * mm; int arh = 360 / 24 * hh; g.fillArc(100, 100, 200, 200, 90, -ars); g.setColor(Color.blue); g.fillArc(130, 130, 140, 140, 90, -arm); g.setColor(Color.magenta); g.fillArc(150, 150, 80, 80, 90, -arh); } void begin() { (new Thread(kk)).start();// 线程启动! } public static void main(String[] args) { ClockPanel a = new ClockPanel(); } } /* * 这个是用来控制画图的线程,每秒刷新 * * @author yanglingfeng * */ class Clock implements Runnable { ClockPanel a = null; Clock(ClockPanel in) { a = in; a.draw(); } @Override public void run() { while (true) { try { a.draw(); Thread.sleep(1000);// 1秒刷新 } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }