#眉標=JavaFX、NetBeans、DSL #副標=從實例學習JavaFX(1) #大標=JavaFX架構概觀與開發入門 #作者=文╱圖 陳廷嘉 ===<反灰>============= Stage { title: "JavaFX Hello" ... scene: Scene { content: Text { ... content: "JavaFX 說:哈囉!" } } } ================ ===<反灰>============= 這齣Stage叫作「JavaFX Hello」,�媄鉿陪茬黥滿A場景�媄銎韙F一個「JavaFX說:哈囉!」的文字看板。 ================ ===<反灰>============= def numOne = 100; def numTwo = 2; var result; add(); function add() { result = numOne + numTwo; println("{numOne} + {numTwo} = {result}"); } 執行結果:100 + 2 = 102 ================ ===<反灰>============= var result; function run(args : String[]) { // 將字串轉換為數字 def numOne = java.lang.Integer.parseInt(args[0]); def numTwo = java.lang.Integer.parseInt(args[1]); println(add(numOne, numTwo)); } function add() { //相同,省略 } ================ ===<反灰>============= 5ms; // 5 毫秒 10s; // 10 秒 30m; // 30 分 1h; // 1 小時 // 建立一個間格3秒自動轉動4次的特效定義 var effect = RotateTransition { duration: 3s node: node repeatCount:4 } ================ ===<反灰>============= // 字串序列,可用days [i]作存取 def days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; // 建立1-5的數字序列 var nums = [1..5]; def weekend = days[5..6]; // 等於["Sat", "Sun"] def weekdays = days[0..<3]; // 等於["Mon", "Tue", "Wed"] def weekend = days[5..]; // 等於["Sat", "Sun"] def nums1 = nums[n | n > 2]; // 等於[3,4,5] insert 6 into nums; // 等於[1,2,3,4,5,6] insert 0 before nums[0]; // 等於[0,1,2,3,4,5] insert 0 after nums[2]; // 等於[1,2,3,0,4,5] delete nums[2]; // 等於[1,2,4,5] delete 2 from nums; // 等於[1,3,4,5] delete nums[1..3]; // 等於[1,5] delete nums; // 等於[] reverse nums // 等於[5,4,3,2,1] ================ ===<反灰>============= class People { public-init var name: String; public-init var age: Integer; } class Greeting { var p: People; function say() { println("Hi, I'm {p.name}"); } } ================ ===<反灰>============= // IGreeting.java interface IGreeting { public void say(); } // Greeting.fx class Greeting extends IGreeting { override function say() {...} } ================ ===<反灰>============= class Foo extends java.io.Serializable, java.io.InputStream, java.io.StringWriter { ... } ================ ===<反灰>============= var john = People { name: “John”, age: 12 } ================ ===<反灰>============= var x = 0; def y = bind x; x = 1; assert y == 1; var theName = “JoJo”; var theAge = 10; var p = bind People { name: theName, age: theAge } theName = “JoJo 2”; assert p.name == “JoJo 2”; ================ ===<反灰>============= Stage { title: "JavaFX Analog Clock"; // 省略,完整程式碼請參考附錄 visible: true; scene: Scene { content: []; } } ================ ===<反灰>============= Group { transforms: Translate { x: centerX, y: centerY } content: [ for (i in [3, 6, 9, 12]) Text { transforms: Translate { x: -5, y: 5 } font: Font { size: 16 } //省略 }, // 省略,完整程式碼請參考附錄 } ================ ===<反灰>============= content: [ ImageView { image: Image { url: "{__DIR__}clock_background.png" } } //省略,完整程式碼請參考附錄 } ================ ============= 參考資料 ●JavaFX官方網站:http://javafx.com/ ●JavaFX官方Tutorial教學:http://java.sun.com/javafx/1/tutorials/ ●JavaFX API線上文件:http://java.sun.com/javafx/1.1/docs/api/ ●類比型時鐘範例:http://java.sun.com/javafx/1/tutorials/build-javafx-nb-app/MyClockProject.zip ================