




已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
代码实现:public class Date public Date(int year, int month) int cols = 1; int days = 1; for(int i=1; iyear; i+) if(i%100!=0) & (i%4=0) | (i%400=0) days += 366; else days += 365; for(int j=1; jmonth; j+) switch(j) case 1: case 3: case 5: case 7: case 8: case 10: case 12: days += 31; break; case 2: if(year%100!=0) & (year%4=0) | (year%400=0) days += 29; else days += 28; break; default: days += 30; break; cols = days % 7; printDate(year, month, cols); public void printDate(int year, int month, int cols) int days = 0; int i = year; int j = month; System.out.println(i+年); System.out.println(t+i+年 +j+月 +cols=+cols); switch(j) case 1: case 3:case 5: case 7: case 8: case 10: case 12: days = 31; break; case 2: if(i%100!=0) & (i%4=0) | (i%400=0) days = 29; else days = 28; break; default: days = 30; break; System.out.println(t日 + t一 + t二 + t三 + t四 + t五 + t六); for(int m=1; m=cols; m+) System.out.print(t); for(int k=1; k=7) System.out.println(); cols = 0; System.out.println(); public static void main(String args) Date d1 = new Date(2014, 10); /输出2014年10月日历 运行截图:表盘制作import javax.swing.*;import java.awt.*;import java.io.*;import java.util.Calendar;import java.awt.event.*;import java.awt.image.BufferedImage;public class ThreadClock extends JFrame implements Runnable private volatile BufferedImage boardDrawing;/volatile是程度较轻的 synchronized private volatile BufferedImage boardDisplaying; public ThreadClock() setTitle(ThreadClock); setSize(300, 300); setLocation(450,200); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setVisible(true); boardDrawing = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_RGB); boardDisplaying = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_RGB); public void paint(Graphics g) g.drawImage(boardDisplaying, 0, 0, null); Override public void run() /本来我这里的循环条件为true,不过测试运行了几次之后发现这个线程并没有被关闭 /内存使用变成了3GB+,任务管理器中满是javaw.exe /后来用this.isShowing()来判断一下,终于可以顺利结束进程了 while(this.isShowing() Graphics g = boardDrawing.getGraphics(); g.setColor(Color.WHITE); g.clearRect(0, 0, boardDrawing.getWidth(), boardDrawing.getHeight();/清除图形 g.fillRect(0, 0, boardDrawing.getWidth(), boardDrawing.getHeight();/填充背景色为白色 /画图 /画出clock的表盘及数字 g.setColor(Color.BLUE); g.drawOval(100, 100, 100, 100); g.drawString(12, 145, 115); g.drawString(6, 145, 195); g.drawString(9, 105, 155); g.drawString(3, 190, 155); /get Instance Time得到当前时间 Calendar c=Calendar.getInstance(); int week=c.get(Calendar.DAY_OF_WEEK); int month=c.get(Calendar.MONTH); int day=c.get(Calendar.DATE); int hour=c.get(Calendar.HOUR_OF_DAY); int minute=c.get(Calendar.MINUTE); int second=c.get(Calendar.SECOND); int year=c.get(Calendar.YEAR); /画出时针分针秒针 DrawHands(g, second/60.0, 40); DrawHands(g, minute/60.0, 32); DrawHands(g, (hour)/12.0, 25); String weekName=星期日,星期一,星期二,星期三,星期四,星期五,星期六; String monthName=一月,二月,三月,四月,五月,六月,七月,八月,九月,十月,十一月,十二月; /画出显示时间的字符串 String timeString=String.format(%s %s - -:-:- %s, weekNameweek,monthNamemonth,day,hour,minute,second,year); g.drawString(timeString, 75, 215); g.drawString(neolone, 240, 280); / 切换前景与背景工作区 BufferedImage tmp = boardDisplaying; boardDisplaying = boardDrawing; boardDrawing = tmp; this.repaint(); try Thread.sleep(500); catch (Exception e) System.out.println(e); /用g画出某根针(时分秒只是长度不同),percent表示从十二点到某指针现在的位置占整个圆周的百分比,length表示长度 private void DrawHands(Graphics g,Double percent,int length) double degree=360*percent; int x=(int)(150+Math.cos(2*Math.PI*(90-degree)/360)*length); int y=(int)(150-Math.sin(2*Math.PI*(90-degr
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年市场营销人员招聘面试实战指南及预测题
- 2025年财务分析师求职面试指南模拟题及参考答案详解
- 2025年特岗教师招聘音乐科目模拟题
- 2025年中学历史教师资格认证考试模拟题及答案
- 电力人员消防知识培训课件
- 2025年环境工程师招聘笔试模拟题及复习策略
- 2025年小学全科特岗教师面试模拟题集
- 2025年网络安全工程师招聘考试题库与解析
- 1到10的教学课件
- 2025年物资储备仓库运输作业流程与调度员招聘考试要点
- 特种畜禽管理办法
- 消防员心理健康教育课件教学
- 医院学术委员会组织职责
- 重庆临时摊点管理办法
- 藏族课件模板
- 学校德育管理工作
- 【生物 四川卷】2025年四川省高考招生统一考试真题生物试卷(真题+答案)
- 2025年观看师德师风警示教育典型案例心得体会
- GB/T 45745-2025道路货物运输车辆装载规范
- 梯子安全培训
- 2025年剑桥商务英语(BEC)初级考试试卷全真模拟试题
评论
0/150
提交评论