




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
JAVA时钟日历报告import java.awt.BorderLayout;import java.awt.Color;import java.awt.Graphics;import java.util.Date; import java.awt.event.*;import javax.swing.*;import javax.swing.border.TitledBorder; import java.util.*;import javax.swing.JPanel; import javax.swing.JTextField; import java.awt.GridLayout;import javax.swing.JFrame; import javax.swing.JLabel;import javax.swing.SwingUtilities;import javax.swing.UIManager; public class Test extends JFrame private static final long serialVersionUID = 1L;/测试 public Test() Clock clock =new Clock(); Calender cal = new Calender(); SuppressWarnings(unused) JPanel jp2 = new JPanel(); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(560,300); setVisible(true); this.setContentPane(clock); this.getContentPane().add(cal,BorderLayout.WEST); setResizable(false); / /画时钟public class DrawClock extends JPanel implements Runnable private static final long serialVersionUID = 1L; Thread newThread; /线程 public int RADIUS = 80; /时钟的半径 /设置时钟位置 public int centerX = 150; /设置时钟x轴 public int centerY = 120; /设置时钟y轴 public int hr, min, sec; /小时,分钟,秒 public int xPoint = new int4; /指针的4个坐标 public int yPoint = new int4; public double hrAlpha, minAlpha, secAlpha, theta; private JTextField timeZone; /启动时钟 public void start() newThread = new Thread(this); newThread.start(); /启动线程 /终止线程 public void stop() newThread = null; SuppressWarnings(deprecation) public void paint(Graphics g) super.paint(g); /画出时钟刻度 double minuteAlpha = Math.PI/30.0; int count = 0; for(double alpha=0; alpha2.0*Math.PI; alpha+=minuteAlpha) int tX = (int)(centerX+RADIUS*0.9*Math.sin(alpha); int tY = (int)(centerY-RADIUS*0.9*Math.cos(alpha); if(count%5 = 0) g.setColor(Color.CYAN); g.fill3DRect(tX, tY, 3, 3, false); if(count%3=0) int m = count /15; switch(m) case 1: g.drawString(3, centerX+RADIUS-18, centerY+5);break; case 2: g.drawString(6, centerX-3, centerY+RADIUS-10);break; case 3: g.drawString(9, centerX-RADIUS+11,centerY+6);break; default: g.drawString(12, centerX-5, centerY-RADIUS+22); else g.setColor(Color.DARK_GRAY); g.fill3DRect(tX, tY, 2, 2, false); count+; /画出时钟时针 g.setColor(Color.gray); / 定义颜色 drawPointer(g, centerX+2, centerY+2, (int)(RADIUS*0.75), hrAlpha); g.setColor(Color.CYAN); / 定义颜色 drawPointer(g, centerX, centerY, (int)(RADIUS*0.75), hrAlpha); /画出分针 g.setColor(Color.gray); / 定义颜色 drawPointer(g, centerX+2, centerY+2, (int)(RADIUS*0.83), minAlpha); g.setColor(Color.CYAN); / 定义颜色 drawPointer(g, centerX, centerY, (int)(RADIUS*0.83), minAlpha); /画出秒针 g.setColor(Color.DARK_GRAY); /定义颜色 g.drawLine( centerX,centerY, (int)(centerX+(int)(RADIUS*0.79)*Math.sin(secAlpha), (int)(centerY-(int)(RADIUS*0.79)*Math.cos(secAlpha) ); setBorder(new TitledBorder(时间); setBackground(Color.white); / 定义颜色 g.drawRect(85, 210, 130, 20); g.setColor(Color.WHITE); g.setColor(Color.DARK_GRAY); Date timeNow = new Date(); g.drawString(timeNow.toLocaleString(), 100,225); public Date getDate() Date timeNow = new Date(); return timeNow; / 刷新图层 public void update(Graphics g) paint(g); / 画出一个帧的图像 public void run() while(newThread != null) repaint(); try Thread.sleep(800); catch(InterruptedException E) Date timeNow = new Date(); SuppressWarnings(deprecation) int hours = timeNow.getHours(); /这里不知道为什么会画横线的 SuppressWarnings(deprecation) int minutes = timeNow.getMinutes(); /这里不知道为什么会画横线的 SuppressWarnings(deprecation) int seconds = timeNow.getSeconds(); /这里不知道为什么会画横线的 hr = hours; min = minutes; sec = seconds; theta = Math.PI/6.0/20.0; hrAlpha = (double)(hr*3600 + min*60 + sec) /(12.0*3600.0)*2.0*Math.PI; minAlpha = (double)(min*60 + sec)/3600.0*2.0*Math.PI; secAlpha = (double)sec/60.0 * 2.0*Math.PI; private void drawPointer(Graphics g, int x, int y, int len, double theta) xPoint0 = (int)(x+len*0.3*Math.sin(theta-Math.PI); yPoint0 = (int)(y-len*0.3*Math.cos(theta-Math.PI); xPoint1 = (int)(xPoint0+len*0.3*Math.sin (theta-(double)(10.0/180)*Math.PI); yPoint1 = (int)(yPoint0-len*0.3*Math.cos (theta-(double)(10.0/180)*Math.PI); xPoint2 = (int)(xPoint0+len * Math.sin(theta); yPoint2 = (int)(yPoint0-len * Math.cos(theta); xPoint3 = (int)(xPoint0+len*0.3*Math.sin (theta+(double)(10.0/180)*Math.PI); yPoint3 = (int)(yPoint0-len*0.3*Math.cos (theta+(double)(10.0/180)*Math.PI); g.fillPolygon(xPoint, yPoint, 4); public JTextField getTimeZone() return timeZone; public void setTimeZone(JTextField timeZone) this.timeZone = timeZone; / /时钟public class Clock extends JPanel private static final long serialVersionUID = 1L; private UIManager.LookAndFeelInfo looks; private DrawClock clock ; SuppressWarnings(unused) private JPanel pane_clock ; JPanel pane_cal; public Clock() super(); looks = UIManager.getInstalledLookAndFeels(); changeTheLookAndFeel(2); clock = new DrawClock(); clock.start(); this.setBackground(Color.GRAY); this.setLayout(new BorderLayout(); this.setOpaque(false); this.add(clock); this.setBorder(new TitledBorder(时间日期); this.setBorder(new TitledBorder(时区); this.setBorder(new TitledBorder(Internet时间); setSize( 300, 300 ); setVisible( true ); private void changeTheLookAndFeel(int i) try UIManager.setLookAndFeel(looksi.getClassName(); SwingUtilities.updateComponentTreeUI(this); catch(Exception exception) exception.printStackTrace(); / /设计日历public class Calender extends JPanel implements ActionListener private static final long serialVersionUID = 1L; public final String HOUR_OF_DAY = null; /定义 SuppressWarnings(rawtypes) JComboBox Month = new JComboBox(); SuppressWarnings(rawtypes) JComboBox Year = new JComboBox(); JLabel Month_l = new JLabel(); JLabel Year_l = new JLabel(); Date now_date = new Date(); JLabel Label_day = new JLabel49; SuppressWarnings(deprecation) int now_year = now_date.getYear() + 1900; SuppressWarnings(deprecation) int now_month = now_date.getMonth(); boolean bool = false; String year_int = null; int month_int; JPanel pane_ym = new JPanel(); JPanel pane_day = new JPanel(); SuppressWarnings(unchecked) public Calender() super(); /设定年月 for (int i = now_year - 10; i = now_year + 20; i+) Year.addItem(i + ); for (int i = 1; i 13; i+) Month.addItem(i + ); Year.setSelectedIndex(10); pane_ym.add(new JLabel( ); pane_ym.add(Year); pane_ym.add(Year_l); Month.setSelectedIndex(now_month); pane_ym.add(Month); pane_ym.add(Month_l); pane_ym.add(new JLabel( ); Month.addActionListener(this); Year.addActionListener(this); /初始化日期并绘制 pane_day.setLayout(new GridLayout(7, 7, 10, 10); for (int i = 0; i 49; i+) Label_dayi = new JLabel( ); pane_day.add(Label_dayi); this.setDay(); this.setLayout(new BorderLayout(); this.add(pane_day, BorderLayout.CENTER); this.add(pane_ym, BorderLayout.NORTH); this.setSize(100,200); this.setBorder(new TitledBorder(日期(D); setSize(300,300); SuppressWarnings(deprecation) void setDay() if (bool) year_int = now_year + ; month_int = now_month; else year_int = Year.getSelectedItem().toString(); month_int = Month.getSelectedIndex(); int year_sel = Integer.parseInt(year_int) - 1900; /获得年份值 /SuppressWarnings(deprecation) Date dt = new Date(year_sel, month_int, 1); /构造一个日期 GregorianCalendar cal = new GregorianCalendar(); /创建一个Calendar实例 cal.setTime(dt); String week = 日, 一,二, 三, 四, 五, 六 ; int day = 0; int day_week = 0; for (int i = 0; i 7; i+) Label_dayi.setText(weeki); /月份 if (month_int = 0|month_int = 2 |month_int = 4 | month_int = 6 | month_int = 9 |month_int = 11) day = 31; else if (month_int = 3 |month_int = 5 | month_int = 7| month_int = 8 |month_int = 10| month_int = 1) day = 30; else if (cal.isLeapYear(year_sel) day = 29; else day = 28; day_week = 7 + dt.getDay(); int count = 1; for (int i = day_week; i day_week + day; count+, i+) if (i % 7 = 0 |i = 13|i = 20|i = 27| i
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 夫妻共同财产中车辆分割及补偿协议书
- 跨境电商企业股东股权分割与风险控制协议
- 离婚子女抚养权及财产分配调解协议
- 物业接管与查验、住宅小区物业设施设备维护合同
- 离婚协议财产分割及子女抚养赔偿协议范本详解
- 离婚财产分割执行起诉范本及程序指引
- 高职招生培训课件
- pe技术员考试题及答案
- 辅警培训国保知识课件
- 农业银行2025广安市秋招笔试性格测试题专练及答案
- 2025年省农垦集团有限公司人员招聘笔试备考附答案详解(完整版)
- 2025年市中区畜牧兽医、动物检疫站事业单位招聘考试真题库及答案
- 2025至2030中国污水处理设备行业商业模式及发展前景与投资报告
- 2025年烟草生产专用设备制造行业研究报告及未来行业发展趋势预测
- 2025至2030中国核反应堆建造行业发展趋势分析与未来投资战略咨询研究报告
- 2025江苏连云港市海州区第二批招聘社区工作者97人考试参考试题及答案解析
- 直播运营基本知识培训课件
- DZ∕T 0215-2020 矿产地质勘查规范 煤(正式版)
- GB/T 13871.1-2022密封元件为弹性体材料的旋转轴唇形密封圈第1部分:尺寸和公差
- GB/T 41696-2022下肢康复训练设备的分类及通用技术条件
- 《红楼梦》中的服饰文化共38张课件
评论
0/150
提交评论