JavaFX
Contents
JavaFX Tools
.fx Dateien kompilieren
Erzeugt .class files.
javafxc myfile.fx
.fx Programme ausfuehren
javafx myfile
JavaFX Script
def und var
Nur vars koennen redefiniert werden. Defs verhalten sich wie Konstanten.
def numOne = 100; def numTwo = 2; var result; result = numOne + numTwo; println("{numOne} + {numTwo} = {result}");
Functions
function add(argOne: Integer, argTwo: Integer) : Integer { result = argOne + argTwo; println("{argOne} + {argTwo} = {result}"); return result; }
Classes
class Address { var street: String; var city: String; var state: String; var zip: Number; }
def myAddress = Address { street : "Parkstrasse"; city : "Wabern"; zip : 3084; } println("{myAddress.street}");
Browser sample
Kleine Vorlage für eine Business-Applikation (Modell und bindings von den UI-Komponenten zum Modell). http://www.claude-glauser.ch/j2ee/javafx/TestmasterJFxClient.html
Main.fx
package testmaster.testmasterjfxclient; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.LayoutInfo; import testmaster.testmasterjfxclient.model.Model; import testmaster.testmasterjfxclient.model.Question; var listView: ListView; def model = Model { selectedQuestion: bind (listView.selectedItem as Question) }; Stage { title: "Binding sample" scene: Scene { width: 350 height: 150 content: [ listView = ListView { layoutX: 10 layoutY: 10 layoutInfo: LayoutInfo {width: 120 height: 100} items: bind model.questions cellFactory: function () { def cell: ListCell = ListCell { node: Label { width: 100 height: 20 text: bind ( (cell.item as Question).title) } } } }, Label { layoutX: 150 layoutY: 50 text: "Titel"; } TextBox { layoutX: 180 layoutY: 50 text: bind model.questionTitle with inverse; } Label { layoutX: 150 layoutY: 80 text: "Text"; } TextBox { layoutX: 180 layoutY: 80 text: bind model.questionText with inverse; } Button { layoutX: 150 layoutY: 110 text: "Neue Frage hinzufügen" action: function() { model.addQuestion(); listView.selectLastRow(); } } ] } }
Model.fx
package testmaster.testmasterjfxclient.model; public class Model { public var testTitle : String = "Mein Test"; public var selectedQuestion : Question on replace oldValue { this.questionTitle = selectedQuestion.title; this.questionText = selectedQuestion.text; } public var questionText : String on replace { selectedQuestion.text = questionText; } public var questionTitle : String on replace { selectedQuestion.title = questionTitle; } public function addQuestion() { var q = Question { title: "NewQuestion"; text: "New text"; } insert q into questions; } public var questions = [ Question { title: "Frage1"; text: "Text1" }, Question { title: "Frage2"; text: "Text2" } Question { title: "Frage3"; text: "Text3" } ]; }
Question.fx
package testmaster.testmasterjfxclient.model; public class Question { public var title:String; public var text:String; }