JavaFX 時(shí)鐘

           

          今天看到這位博客的博主,把Chris Oliver 寫(xiě)的時(shí)鐘改了一些代碼,變成這個(gè)樣子,呵呵,有興趣的朋友可以參考下學(xué)習(xí)下面的源代碼:
           1import javafx.ui.*;
           2import javafx.ui.canvas.*;
           3import java.util.Date;
           4
           5public class Timer {
           6    private attribute elapsed: Number;
           7    public attribute minutes: Number;
           8    public attribute seconds: Number;
           9    public attribute hours: Number;
          10    public attribute running: Boolean;
          11}

          12
          13attribute Timer.elapsed = bind
          14if running then
          15[1..60] dur 60000 linear
          16while running
          17continue if true
          18else 0;
          19
          20trigger on Timer.elapsed = value {
          21    var now = new Date();
          22    minutes = now.getMinutes();
          23    seconds = now.getSeconds() +
          24    [.35,0.34 .. 0.0] dur 350 +
          25    (now.getTime() % 1000)/1000;
          26    hours = now.getHours();
          27}

          28
          29public class Clock extends CompositeNode {
          30    public attribute ticking: Boolean;
          31}

          32
          33operation Clock.composeNode() {
          34    var t = Timer {running: bind ticking};
          35    return Group {
          36        transform: [translate(5,5),scale(1,1)]
          37        var secs = bind t.seconds
          38        var mins = bind t.minutes + secs/60
          39        var hrs = bind t.hours + mins/60
          40        content:
          41        [
          42        Rect {
          43            height: 200
          44            width: 200
          45            fill: white
          46        }
          ,
          47        ImageView {
          48            transform: []
          49            image: Image {url: "http://sellmic.com/lab/dev/jfx/clock/images/clock_face.png"}
          50        }
          ,
          51        Group {
          52            var hourHand =
          53            ImageView {
          54                transform: bind rotate(hrs*30,255,245)
          55                image: Image {url: "http://sellmic.com/lab/dev/jfx/clock/images/hour_hand.png"}
          56            }

          57
          58            var minuteHand =
          59            ImageView {
          60                transform: bind rotate(mins *6,255,245)
          61                image: Image {url: "http://sellmic.com/lab/dev/jfx/clock/images/minute_hand.png"}
          62            }

          63            
          64            var secondHand =
          65            ImageView {
          66                transform: bind rotate(t.seconds * 6,255,245)
          67                image: Image {url: "http://sellmic.com/lab/dev/jfx/clock/images/second_hand.png"}
          68            }

          69
          70            content: [hourHand, minuteHand, secondHand]
          71        }
          ,
          72        ImageView {
          73            transform: []
          74            image: Image {url: "http://sellmic.com/lab/dev/jfx/clock/images/pin.png"}
          75        }
          ]
          76    }
          ;
          77}

          78
          79Clock {ticking: true} 
          80
          81

          posted on 2007-05-21 21:39 快譯站 閱讀(626) 評(píng)論(0)  編輯  收藏 所屬分類: 技術(shù)前沿

          導(dǎo)航

          留言簿(3)

          隨筆分類

          隨筆檔案

          友情鏈接

          最新評(píng)論

          主站蜘蛛池模板: 神农架林区| 江阴市| 齐齐哈尔市| 剑阁县| 平昌县| 西贡区| 三台县| 弋阳县| 吉木萨尔县| 孝昌县| 建昌县| 凤庆县| 镇雄县| 宁南县| 祁连县| 保康县| 海宁市| 莲花县| 上蔡县| 蒙山县| 丽江市| 利川市| 微山县| 子长县| 万盛区| 阳春市| 浦城县| 勃利县| 乡宁县| 千阳县| 常熟市| 莎车县| 横峰县| 芷江| 巴青县| 扎兰屯市| 枣阳市| 疏附县| 宣化县| 西丰县| 宜都市|