文件名称:细分时钟刻度算法.txt

  • 所属分类:
  • WEB源码
  • 资源属性:
  • [Text]
  • 上传时间:
  • 2011-08-20
  • 文件大小:
  • 4.17kb
  • 下载次数:
  • 0次
  • 提 供 者:
  • hellosoft010@sina.com
  • 相关连接:
  • 下载说明:
  • 别用迅雷下载,失败请重下,重下不扣分!

介绍说明--下载内容均来自于网络,请自行研究使用

import java.awt.*; import javax.swing.*; public class Exercise8_12 extends Jfr a me { // Main method with three auguments: // args[0]: hour // args[1]: minute // args[2]: second public static void main(String[] args) { // Declare hour, minute, and second values int hour = 0; int minute = 0; int second = 0; // Check usage and get hour, minute, second if (args.length > 3) { System.out.println( "Usage: java DisplayClock hour minute second"); System.exit(0); } else if (args.length == 3) { hour = new Integer(args[0]).intValue(); minute = new Integer(args[1]).intValue(); second = new Integer(args[2]).intValue(); } else if (args.length == 2) { hour = new Integer(args[0]).intValue(); minute = new Integer(args[1]).intValue(); } else if (args.length == 1) { hour = new Integer(args[0]).intValue(); } // Create a fr a me to hold the clock Exercise8_12 fr a me = new Exercise8_12(); fr a me.setTitle("Exercise 8.12: Display Clock"); fr a me.getContentPane().add(new DrawClock(hour, minute, second)); fr a me.setDefaultCloseOperation(Jfr a me.EXIT_ON_CLOSE); fr a me.setSize(300, 350); fr a me.setVisible(true); } } class DrawClock extends JPanel { private int hour; private int minute; private int second; protected int xCenter, yCenter; protected int clockRadius; // Construct a clock panel public DrawClock(int hour, int minute, int second) { this.hour = hour; this.minute = minute; this.second = second; } // Draw the clock public void paintComponent(Graphics g) { super.paintComponent(g); // Initialize clock parameters clockRadius = (int)(Math.min(getSize().width, getSize().height)*0.7*0.5); xCenter = (getSize().width)/2; yCenter = (getSize().height)/2; // Draw circle g.setColor(Color.black); g.drawOval(xCenter - clockRadius,yCenter - clockRadius, 2*clockRadius, 2*clockRadius); g.drawString("12",xCenter-5, yCenter-clockRadius); g.drawString("9",xCenter-clockRadius-10,yCenter+3); g.drawString("3",xCenter+clockRadius,yCenter+3); g.drawString("6",xCenter-3,yCenter+clockRadius+10); // Draw second hand int sLength = (int)(clockRadius*0.85); int xSecond = (int)(xCenter + sLength*Math.sin(second*(2*Math.PI/60))); int ySecond = (int)(yCenter - sLength*Math.cos(second*(2*Math.PI/60))); g.setColor(Color.red); g.drawLine(xCenter, yCenter, xSecond, ySecond); // Draw minute hand int mLength = (int)(clockRadius*0.75); int xMinute = (int)(xCenter + mLength*Math.sin(minute*(2*Math.PI/60))); int yMinute = (int)(yCenter - mLength*Math.cos(minute*(2*Math.PI/60))); g.setColor(Color.blue); g.drawLine(xCenter, yCenter, xMinute, yMinute); // Draw hour hand int hLength = (int)(clockRadius*0.6); int xHour = (int)(xCenter + hLength*Math.sin((hour+minute/60.0)*(2*Math.PI/12))); int yHour = (int)(yCenter - hLength*Math.cos((hour+minute/60.0)*(2*Math.PI/12))); g.setColor(Color.green); g.drawLine(xCenter, yCenter, xHour, yHour); // Display current time in string g.setColor(Color.red); String time = "Hour: " + hour + " Minute: " + minute + " Second: " + second; FontMetrics fm = g.getFontMetrics(); g.drawString(time, (getSize().width - fm.stringWidth(time))/2, yCenter+clockRadius+30); // Display more details on the clock for (int i=0; i<60; i++) { double percent; if (i%5 == 0) { percent = 0.9; } else { percent = 0.95; } //细分时钟刻度 int xOuter = (int)(xCenter + clockRadius*Math.sin(i*(2*Math.PI/60))); int yOuter = (int)(yCenter - clockRadius*Math.cos(i*(2*Math.PI/60))); int xInner = (int)(xCenter + percent*clockRadius*Math.sin(i*(2*Math.PI/60))); int yInner = (int)(yCenter - percent*clockRadius*Math.cos(i*(2*Math.PI/60))); g.drawLine(xOuter, yOuter, xInner, yInner); } } }
(系统自动生成,下载前可以参看下载内容)

下载文件列表

压缩包 : 细分时钟刻度算法.txt 列表
压缩包 : 细分时钟刻度算法.rar 列表
细分时钟刻度算法.txt

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度更多...
  • 请直接用浏览器下载本站内容,不要使用迅雷之类的下载软件,用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.

相关评论

暂无评论内容.

发表评论

*主  题:
*内  容:
*验 证 码:

源码中国 www.ymcn.org