資源簡介
本次Java項目以“時間的腳步”為題目,其中包含萬年歷和時鐘。由主界面進入系統,分別查看日歷和時鐘。日歷的功能的實現:可以顯示當前的年、月、日和星期。同時也可以查詢,分別選擇年和月后顯示所要查詢的日期,并顯示當前月的日歷。時鐘功能的實現:實現簡單的動態(tài)時鐘顯示,以圖形和數字兩種方式顯示當前的時間。

代碼片段和文件信息
import?javax.swing.*;
import?javax.swing.Timer;
import?java.awt.*;
import?java.awt.event.*;
import?java.util.*;
public?class?Clock?extends?Jframe?implements?ActionListener
{
?????int?xyx0y0rholds_xolds_yoldm_xoldm_yoldh_xoldh_y
?????ssmmhhold_mold_hang;
?????final?double?RAD=Math.PI/180;
?????public?Clock()
?????{
???? ?super(“天使的腳步“);
???? ?setDefaultCloseOperation(3);
???? ?setSize(300300);
???? ?setBackground(Color.black);
???? ?setLocation(300150);
???? ?setResizable(false);
???? ?show();
???? ?int?delay=1000;
???? ?Timer?timer=new?Timer(delaynew?TimerListener());
???? ?timer.start();
? JButton?exit=new?JButton(“退出“);
exit.addActionListener(this);
add(exitBorderLayout.SOUTH);
???? ?
?????}
?class?TimerListener?implements?ActionListener
?{
?public?void?actionPerformed(ActionEvent?evt)
?{
?setCurrentTime();
?repaint();
?}
?}
public?void?paint(Graphics?g)
{
?Graphics2D?g2D=(Graphics2D)g;
?Insets?insets=getInsets();
?int?L=insets.left/2T=insets.top/2;
?h=getSize().height;
?g.setColor(Color.white);
?//畫圓
?g2D.setStroke(new?BasicStroke(4.0f));
?g.drawOval(L+40T+40?h-80?h-80);
?r=h/2-40;
?x0=40+r-5+L;
?y0=40+r-5-T;
?ang=60;
?for(int?i=1;i<=12;i++)
?{
?x=(int)((r+10)*Math.cos(RAD*ang)+x0);
?y=(int)((r+10)*Math.sin(RAD*ang)+y0);
?g.drawString(““+ixh-y);
?ang-=30;
?}
?Calendar?now?=new?GregorianCalendar();
?int?nowh=now.get(Calendar.HOUR_OF_DAY);
?int?nowm=now.get(Calendar.MINUTE);
?int?nows=now.get(Calendar.SECOND);
?String?st;
?if(nowh<10)?st=“0“+nowh;
?else?st=““+nowh;
?if(nowm<10)?st+=“:0“+nowm;
?else?st+=“:“+nowm;
?if(nows<10)?st+=“:0“+nows;
?else?st+=“:“+nows;
??
?g.setColor(Color.pink);
?g.fillRect(L?T?50?28);
?g.setColor(Color.blue);
?g.drawString(st?L+2?T+26);
?ss=90-nows*6;
?mm=90-nowm*6;
?hh=90-nowh*30-nowm/2;
?x0=r+40+L;
?y0=r+40+T;
?g2D.setStroke(new?BasicStroke(1.2f));
?
if(olds_x>0)
?{
?g.setColor(getBackground());
?g.drawLine(x0?y0olds_xh-olds_y?);;
?}
?else
?{
?old_m=mm;
?old_h=hh;
?
?}
?x=(int)(r*0.9*Math.cos(RAD*ss))+x0;
?y=(int)(r*0.9*Math.sin(RAD*ss))+y0-2*T;
?g.setColor(Color.yellow);
?g.drawLine(x0y0?xh-y);
?olds_x=x;
?olds_y=y;
?g2D.setStroke(new?BasicStroke(2.2f));
?if(old_m!=mm)
?{
?g.setColor(getBackground());
?g.drawLine(x0?y0oldm_xh-oldm_y?);
?
??????}
?
?x=(int)(r*0.7*Math.cos(RAD*mm))+x0;
?y=(int)(r*0.7*Math.sin(RAD*mm))+y0-2*T;
?g.setColor(Color.green);
?g.drawLine(x0y0?xh-y);
?oldm_x=x;
?oldm_y=y;
?old_m=mm;
?g2D.setStroke(new?BasicStroke(3.4f));
?if(old_h!=hh)
?{
?g.setColor(getBackground());
?g.drawLine(x0
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????232??2012-06-12?22:36??Time\.classpath
?????文件????????380??2012-06-12?22:36??Time\.project
?????文件????????643??2012-06-13?13:43??Time\bin\Clock$TimerListener.class
?????文件???????4875??2012-06-13?13:43??Time\bin\Clock.class
?????文件???????1137??2012-06-13?13:54??Time\bin\MyCalendar$1.class
?????文件???????1068??2012-06-13?13:54??Time\bin\MyCalendar$2.class
?????文件???????1273??2012-06-13?13:54??Time\bin\MyCalendar$3.class
?????文件???????1396??2012-06-13?13:54??Time\bin\MyCalendar$4.class
?????文件????????987??2012-06-13?13:54??Time\bin\MyCalendar$CalendarTable.class
?????文件???????4874??2012-06-13?13:54??Time\bin\MyCalendar.class
?????文件???????1625??2012-06-13?13:45??Time\bin\TimeAndCalendar.class
?????文件???????3519??2012-06-13?13:43??Time\src\Clock.java
?????文件???????6949??2012-06-13?13:54??Time\src\MyCalendar.java
?????文件???????1116??2012-06-13?13:45??Time\src\TimeAndCalendar.java
?????目錄??????????0??2012-06-13?12:16??Time\bin
?????目錄??????????0??2012-06-13?11:22??Time\src
?????目錄??????????0??2012-06-12?22:36??Time
-----------?---------??----------?-----??----
????????????????30074????????????????????17
- 上一篇:用Java實現圖形界面猜數字大小的游戲
- 下一篇:java 實現十六進制數轉為圖片
評論
共有 條評論