卡通時(shí)鐘的設(shè)計(jì)_第1頁(yè)
卡通時(shí)鐘的設(shè)計(jì)_第2頁(yè)
卡通時(shí)鐘的設(shè)計(jì)_第3頁(yè)
卡通時(shí)鐘的設(shè)計(jì)_第4頁(yè)
卡通時(shí)鐘的設(shè)計(jì)_第5頁(yè)
已閱讀5頁(yè),還剩7頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、卡通時(shí)鐘的設(shè)計(jì)姓名: 學(xué)號(hào): 專業(yè): 班級(jí):一、概述JAVA程序設(shè)計(jì)是計(jì)算機(jī)相關(guān)專業(yè)的必修專業(yè)基礎(chǔ)課程,其實(shí)踐性、應(yīng)用性很強(qiáng)。實(shí)踐教學(xué)環(huán)節(jié)是必不可少的一個(gè)重要環(huán)節(jié)。本課程的程序設(shè)計(jì)專題實(shí)際是計(jì)算機(jī)相關(guān)專業(yè)學(xué)生學(xué)習(xí)完JAVA程序設(shè)計(jì)課程后,進(jìn)行的一次全面的綜合訓(xùn)練,JAVA程序設(shè)計(jì)的設(shè)計(jì)目的是加深對(duì)理論教學(xué)內(nèi)容的理解和掌握,使學(xué)生較系統(tǒng)地掌握程序設(shè)計(jì)及其在網(wǎng)絡(luò)開發(fā)中的廣泛應(yīng)用,基本方法及技巧,為學(xué)生綜合運(yùn)用所學(xué)知識(shí),利用軟件工程為基礎(chǔ)進(jìn)行軟件開發(fā)、并在實(shí)踐應(yīng)用方面打下一定基礎(chǔ)。按課程設(shè)計(jì)指導(dǎo)書提供的課題,要求學(xué)生在自行完成各個(gè)操作環(huán)節(jié),并能實(shí)現(xiàn)且達(dá)到舉一反三的目的,完成一個(gè)項(xiàng)目解決一類問題。要求

2、學(xué)生能夠全面、深入理解和熟練掌握所學(xué)內(nèi)容,并能夠用其分析、設(shè)計(jì)和解答類似問題;對(duì)此能夠較好地理解和掌握,能夠進(jìn)行簡(jiǎn)單分析和判斷;能編寫出具有良好風(fēng)格的程序;掌握J(rèn)AVA程序設(shè)計(jì)的基本技能和面向?qū)ο蟮母拍詈头椒ǎ涣私舛嗑€程、安全和網(wǎng)絡(luò)等編程技術(shù)。同時(shí)培養(yǎng)學(xué)生進(jìn)行分析問題、解決問題的能力;培養(yǎng)學(xué)生進(jìn)行設(shè)計(jì)分析、設(shè)計(jì)方法、設(shè)計(jì)操作與測(cè)試、設(shè)計(jì)過程的觀察、理解和歸納能力的提高。二、主要內(nèi)容本次設(shè)計(jì)主要是要時(shí)鐘有良好的界面,比較簡(jiǎn)潔美觀,有很強(qiáng)的實(shí)用性,實(shí)現(xiàn)程序與電腦的時(shí)間的同步,可以顯示時(shí)鐘,可以顯示分針秒針,并且也可以在相應(yīng)位置調(diào)整時(shí)間。而且初始運(yùn)行會(huì)自動(dòng)與電腦的時(shí)間校對(duì),一般默認(rèn)為同步,還要可以自

3、己再次調(diào)節(jié),提高了實(shí)用性。本系統(tǒng)共包括1個(gè)java源文件。1、Clock源文件是本程序的主函數(shù)其作用是初始化棋盤。2、setCurrentTime源文件實(shí)現(xiàn)電腦設(shè)置時(shí)間。3、源文件為時(shí)針.4、paintSecondPointer源文件實(shí)現(xiàn)人與電腦設(shè)置秒針.5、paintMinuteDot源文件人與電腦 三、程序代碼電腦設(shè)置時(shí)間public void setCurrentTime(Date time) this.currentTime.setTime(time); public void setCurrentTime(long millis) this.currentTime.setTimeIn

4、Millis(millis); public Dimension getPreferredSize() Insets insets = getInsets(); int r = (int) (radius = -1 ? 0 : radius*(1+s)+1; return new Dimension(r * 2 + insets.left + insets.right,r * 2 + insets.top + insets.bottom); protected void paintComponent(Graphics g) super.paintComponent(g); Graphics2D

5、 g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Insets insets = getInsets(); int wid = getWidth() - insets.left - insets.right; int hei = getHeight() - insets.top - insets.bottom; int r = (int) (Math.min(wid, hei) / 2 / (1+s); g2d.tran

6、slate(insets.left + r * (1+s), insets.top + r * (1+s); g2d.scale(1, -1); for (int i = 0; i 60; i+) int angle = 90 - i * 6; double pos = calcPos(r, angle); paintMinuteDot(r, g2d, pos0, pos1, i % 5 = 0); paintHourPointer(r, g2d); paintMinutePointer(r, g2d); paintSecondPointer(r, g2d); paintCenterPoint

7、(g2d); g2d.scale(1, -1); g2d.translate(-insets.left - r * (1+s), -insets.top - r * (1+s); private void paintCenterPoint(Graphics2D g2d) g2d.setColor(Color.BLUE); Rectangle2D rect = new Rectangle2D.Double(-2, -2, 4, 4); g2d.fill(rect); private void paintMinutePointer(int r, Graphics2D g2d) int minute

8、 = currentTime.get(Calendar.MINUTE); int second = currentTime.get(Calendar.SECOND); double angle = 90 - (minute + second / 60.0) * 6; Shape pointerShape = createPointerShape(r * 0.8, r * 0.04, r * 0.08, angle); g2d.setColor(Color.LIGHT_GRAY); g2d.fill(pointerShape); g2d.setColor(Color.DARK_GRAY); g2

9、d.draw(pointerShape); 設(shè)置秒針private void paintHourPointer(int r, Graphics2D g2d) int hour = currentTime.get(Calendar.HOUR); int minute = currentTime.get(Calendar.MINUTE); int second = currentTime.get(Calendar.SECOND); double angle = 90 - (hour + minute / 60.0 + second / 3600.0) * 30; Shape pointerShap

10、e = createPointerShape(r * 0.6, r * 0.06, r * 0.1, angle); g2d.setColor(Color.LIGHT_GRAY); g2d.fill(pointerShape); g2d.setColor(Color.DARK_GRAY); g2d.draw(pointerShape); private Shape createPointerShape(double r1, double r2, double r3, double angle) GeneralPath gp = new GeneralPath(); double pos = c

11、alcPos(r1, angle); double pos1 = calcPos(r2, angle + 90); gp.append(new Line2D.Double(pos0, pos1, pos10, pos11), true); double pos2 = calcPos(r3, angle + 180); gp.lineTo(float)pos20, (float)pos21); double pos3 = calcPos(r2, angle + 270); gp.lineTo(float)pos30, (float)pos31); gp.closePath(); return g

12、p; private void paintSecondPointer(int r, Graphics2D g2d) g2d.setColor(Color.BLACK); int second = currentTime.get(Calendar.SECOND); int angle = 90 - second * 6; double pos = calcPos(r * 0.9, angle); double pos1 = calcPos(r * 0.2, angle + 180); Line2D line = new Line2D.Double(pos10, pos11, pos0, pos1

13、); g2d.draw(line); 設(shè)置分針private void paintMinuteDot(int r, Graphics2D g2d, double x, double y, boolean flag) g2d.setColor(flag ? Color.RED : Color.BLACK); if (flag) /Rectangle2D rect = new Rectangle2D.Double( Ellipse2D rect = new Ellipse2D.Double( x - r * s, y - r * s, r * s * 2, r * s * 2); g2d.fill

14、(rect); else /Rectangle2D rect = new Rectangle2D.Double( Ellipse2D rect = new Ellipse2D.Double( x - r * 0.02, y - r * 0.02, r * 0.04, r * 0.04); g2d.fill(rect); private double calcPos(double r, double angle) double radian = Math.toRadians(angle); double x = r * Math.cos(radian); double y = r * Math.

15、sin(radian); return new double x, y; public static void main(String args) try UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName(); catch (Exception e) e.printStackTrace(); final Clock clock = new Clock(50); clock.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10); JFrame f = ne

16、w JFrame( C0942 0901024233 郭富康); /f.setBounds(380,200,500,600); f.getContentPane().add(clock, BorderLayout.CENTER); f.pack(); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); new Thread() public void run() while (true) try Thread.sleep(1000); catch

17、 (InterruptedException ex) ex.printStackTrace(); clock.setCurrentTime(System.currentTimeMillis(); clock.repaint(); .start(); int y1 = (int)(r - 10) * Math.cos(rad * s);g.drawLine(x + r, y + r, x + r + x1, y + r - y1);分針g.setColor(Color.BLUE);x1 = (int)(r - r / 2.5) * Math.sin(rad * m);y1 = (int)(r -

18、 r / 2.5) * Math.cos(rad * m);g.drawLine(x + r, y + r, x + r + x1, y + r - y1);g.setColor(Color.CYAN);x1 = (int)(r - r / 1.5) * Math.sin(rad * h);y1 = (int)(r - r / 1.5) * Math.cos(rad * h);g.drawLine(x + r, y + r, x + r + x1, y + r - y1);g.setColor(Color.YELLOW);int d = 29;for (int i = 1; i = 12; i

19、+) x1 = (int)(r - 10) * Math.sin(rad * d);y1 = (int)(r - 10) * Math.cos(rad * d);g.drawString(i + , x + r + x1 - 4, x + r - y1 + 5);d+=30;d = 0;for (int i = 0; i = 360) s = 0;m+=6;if (m = 72 | m = 144 | m = 216 | m = 288) h+=6;if (m = 360) m = 0;h+=6;if (h =360) h = 0;this.repaint();int x, y, r;int

20、h, m, s;double rad = Math.PI / 180;public ClockPaint(int x, int y, int r) this.x = x;this.y = y;this.r = r;Calendar now = new GregorianCalendar();s = now.get(Calendar.SECOND) * 6;m = now.get(Calendar.MINUTE) * 6;h = (now.get(Calendar.HOUR_OF_DAY) - 12) * 30 + now.get(Calendar.MINUTE) / 12 * 6;Thread

21、 t = new Thread(this);t.start();public void paint(Graphics g) super.paint(g);g.setColor(Color.BLACK);g.fillRect(0, 0, r * 3, r * 3);g.setColor(Color.WHITE);g.drawOval(x, y, r * 2, r * 2);g.setColor(Color.RED);int x1 = (int)(r - 10) * Math.sin(rad * s);繪制鐘面 public void paintComponent(Graphics g) supe

22、r.paintComponent(g); g.drawOval(100, 5, 120, 120); g.drawOval(101, 6, 118, 118); double hourAngle = 2 * Math.PI * (seconds - 3 * 60 * 60) / (12 * 60 * 60); double minuteAngle = 2 * Math.PI * (seconds - 15 * 60) / (60 * 60); double secondAngle = 2 * Math.PI * (seconds - 15) / 60; public void timeElap

23、sed(Timer1 t) calendar.setTime(new Date(); if(MyTimer1.count=1) int a=1; seconds=MyTHour*60*60+MyTMinute*60+MyTSecond; seconds+=a;/a為秒自加 repaint(); else seconds = calendar.get(Calendar.HOUR) * 60 * 60 + calendar.get(Calendar.MINUTE) * 60 + calendar.get(Calendar.SECOND); repaint(); 顯示當(dāng)前時(shí)間 public void displayCurrentTime() JOptionPane.showMessageDialog(null,intHour+:+intMinute+:+intSecond); 設(shè)定當(dāng)前時(shí)間 public void setCurrentTime() String strTemp=JOptionPane.showInputDialog(null,請(qǐng)輸入當(dāng)前小時(shí)(24小時(shí)制):); int iHour=Integer.parseInt(strTemp); strT

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論