资源描述:
《java时钟日历报告期末课程设计》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、JAVA时钟日历报告importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Graphics;importjava.util.Date;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.border.TitledBorder;importjava.util.*;importjavax.swing.JPanel;importjavax.swing.JTextField;importjava.awt.Gri
2、dLayout;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.SwingUtilities;importjavax.swing.UIManager;publicclassTestextendsJFrame{privatestaticfinallongserialVersionUID=1L;//测试publicTest(){Clockclock=newClock();Calendercal=newCalender();@SuppressWarnings("u
3、nused")JPaneljp2=newJPanel();setLocationRelativeTo(null);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setSize(560,300);setVisible(true);this.setContentPane(clock);this.getContentPane().add(cal,BorderLayout.WEST);setResizable(false);}//////////////////////////////////////画时
4、钟publicclassDrawClockextendsJPanelimplementsRunnable{privatestaticfinallongserialVersionUID=1L;ThreadnewThread;//线程publicintRADIUS=80;//时钟的半径//设置时钟位置publicintcenterX=150;//设置时钟x轴publicintcenterY=120;//设置时钟y轴publicinthr,min,sec;//小时,分钟,秒publicint[]xPoint=newint[4];//指针的4个坐标pu
5、blicint[]yPoint=newint[4];publicdoublehrAlpha,minAlpha,secAlpha,theta;privateJTextFieldtimeZone;//启动时钟publicvoidstart(){newThread=newThread(this);newThread.start();//启动线程}//终止线程publicvoidstop(){newThread=null;}@SuppressWarnings("deprecation")publicvoidpaint(Graphicsg){super.
6、paint(g);//画出时钟刻度doubleminuteAlpha=Math.PI/30.0;intcount=0;for(doublealpha=0;alpha<2.0*Math.PI;alpha+=minuteAlpha){inttX=(int)(centerX+RADIUS*0.9*Math.sin(alpha));inttY=(int)(centerY-RADIUS*0.9*Math.cos(alpha));if(count%5==0){g.setColor(Color.CYAN);g.fill3DRect(tX,tY,3,3,fal
7、se);if(count%3==0){intm=count/15;switch(m){case1:g.drawString("3",centerX+RADIUS-18,centerY+5);break;case2:g.drawString("6",centerX-3,centerY+RADIUS-10);break;case3:g.drawString("9",centerX-RADIUS+11,centerY+6);break;default:g.drawString("12",centerX-5,centerY-RADIUS+22);}}}
8、else{g.setColor(Color.DARK_GRAY);g.fill3DRect(tX,tY,2,2,false);}count++;}//