<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    用JAVA做小時鐘

    Posted on 2006-09-03 07:08 久城 閱讀(1007) 評論(0)  編輯  收藏 所屬分類: JavaTest

    學JAVA 做的第一個GUI程序......
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;

    class Clock extends JFrame
    {
    ?public static double PI = 3.14159265;
    ?Calendar now;
    ?int hh;
    ?int mm;
    ?int ss;
    ?Clock()
    ?{
    ??super("我的時鐘");
    ??setSize(400,400);
    ??setVisible(true);
    ?}
    ?public void paint(Graphics g)
    ?{
    ??g.setColor(Color.WHITE);
    ??g.fillRoundRect(100,100,200,200,200,200);
    ??g.setColor(Color.BLACK);
    ??g.drawString("1",(int)(200-2+100*(Math.sin(30*2*PI/360))),(int)(200+10-100*(Math.cos(30*2*PI/360))));
    ??g.drawString("2",(int)(200-6+100*(Math.sin(30*2*2*PI/360))),(int)(200+10-100*(Math.cos(30*2*2*PI/360))));
    ??g.drawString("3",(int)(200-7+100*(Math.sin(30*3*2*PI/360))),(int)(200-100*(Math.cos(30*3*2*PI/360))));
    ??g.drawString("4",(int)(200-6+100*(Math.sin(30*4*2*PI/360))),(int)(200-100*(Math.cos(30*4*2*PI/360))));
    ??g.drawString("5",(int)(200-2+100*(Math.sin(30*5*2*PI/360))),(int)(200-2-100*(Math.cos(30*5*2*PI/360))));
    ??g.drawString("6",(int)(200+100*(Math.sin(30*6*2*PI/360))),(int)(200-100*(Math.cos(30*6*2*PI/360))));
    ??g.drawString("7",(int)(200+100*(Math.sin(30*7*2*PI/360))),(int)(200-100*(Math.cos(30*7*2*PI/360))));
    ??g.drawString("8",(int)(200+100*(Math.sin(30*8*2*PI/360))),(int)(200-100*(Math.cos(30*8*2*PI/360))));
    ??g.drawString("9",(int)(200+100*(Math.sin(30*9*2*PI/360))),(int)(200-100*(Math.cos(30*9*2*PI/360))));
    ??g.drawString("10",(int)(200+2+100*(Math.sin(30*10*2*PI/360))),(int)(200+2-100*(Math.cos(30*10*2*PI/360))));
    ??g.drawString("11",(int)(200+100*(Math.sin(30*11*2*PI/360))),(int)(200+10-100*(Math.cos(30*11*2*PI/360))));
    ??g.drawString("12",(int)(200+100*(Math.sin(30*12*2*PI/360))),(int)(200+10-100*(Math.cos(30*12*2*PI/360))));
    ??g.setColor(Color.RED);

    ??Calendar now=Calendar.getInstance();
    ??int hh=now.get(Calendar.HOUR_OF_DAY);//小時
    ??int mm=now.get(Calendar.MINUTE);//分鐘
    ??int ss=now.get(Calendar.SECOND);// 秒
    ??g.drawLine(200,200,(int)(200+90*(Math.sin(6*ss*2*PI/360))),(int)(200-90*(Math.cos(6*ss*2*PI/360)))); //畫秒針
    ??g.setColor(Color.black);
    ??g.drawLine(200,200,(int)(200+70*(Math.sin(6*mm*2*PI/360))),(int)(200-70*(Math.cos(6*mm*2*PI/360))));//畫分針
    ??g.setColor(Color.blue);
    ??g.drawLine(200,200,(int)(200+50*(Math.sin((30*hh+0.5*mm)*2*PI/360))),(int)(200-50*(Math.cos((30*hh+0.5*mm)*2*PI/360)))); //畫時針
    ??try{Thread.sleep(500);}catch(Exception e){}
    ??repaint();??
    ?}

    ?public static void main(String[] args)
    ?{
    ??
    ??Clock c = new Clock();
    ??c.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ??
    ?}
    }



    歡迎來訪!^.^!
    本BLOG僅用于個人學習交流!
    目的在于記錄個人成長.
    所有文字均屬于個人理解.
    如有錯誤,望多多指教!不勝感激!

    Copyright © 久城

    主站蜘蛛池模板: 亚洲精品亚洲人成在线| 亚洲一卡2卡4卡5卡6卡在线99| 无码天堂亚洲国产AV| 我想看一级毛片免费的| 亚洲六月丁香六月婷婷色伊人| 114级毛片免费观看| 亚洲欧洲高清有无| 特级做A爰片毛片免费69| 国产精品亚洲片在线va| 久久久久久99av无码免费网站| 亚洲免费二区三区| 操美女视频免费网站| 亚洲日韩一区精品射精| 免费永久国产在线视频| 一区免费在线观看| 黑人精品videos亚洲人| 久久伊人免费视频| 亚洲AV成人噜噜无码网站| 女人让男人免费桶爽30分钟 | 亚洲AV无码欧洲AV无码网站| 抽搐一进一出gif免费视频| 亚洲精品无码成人片久久| 国产免费爽爽视频在线观看| 久久亚洲美女精品国产精品| 成年女人免费视频播放体验区 | 精品无码一区二区三区亚洲桃色| 一个人免费日韩不卡视频| 亚洲短视频在线观看| 欧美大尺寸SUV免费| 国产成人亚洲精品无码AV大片| 久久久久国产成人精品亚洲午夜| 国产午夜精品免费一区二区三区 | 夫妻免费无码V看片| 一级特黄色毛片免费看| 老色鬼久久亚洲AV综合| 国产成人免费福利网站| 四虎成人精品永久免费AV| 亚洲精品自偷自拍无码| 亚洲日韩精品一区二区三区| 丁香花免费完整高清观看| 一级做a爰黑人又硬又粗免费看51社区国产精品视|