JavaFX 時(shí)鐘

今天看到這位博客的博主,把Chris Oliver 寫(xiě)的時(shí)鐘改了一些代碼,變成這個(gè)樣子,呵呵,有興趣的朋友可以參考下學(xué)習(xí)下面的源代碼:
1
import javafx.ui.*;
2
import javafx.ui.canvas.*;
3
import java.util.Date;
4
5
public 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
13
attribute Timer.elapsed = bind
14
if running then
15
[1..60] dur 60000 linear
16
while running
17
continue if true
18
else 0;
19
20
trigger 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
29
public class Clock extends CompositeNode
{
30
public attribute ticking: Boolean;
31
}
32
33
operation 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
79
Clock
{ticking: true}
80
81

2

3

4

5



6

7

8

9

10

11

12

13

14

15

16

17

18

19

20



21

22

23

24

25

26

27

28

29



30

31

32

33



34



35



36

37

38

39

40

41

42



43

44

45

46

47



48

49



50

51



52

53



54

55



56

57

58

59



60

61



62

63

64

65



66

67



68

69

70

71

72



73

74



75

76

77

78

79



80

81

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