JavaFX With Netbeans IDE

 

JavaFX with NetBeans IDE

 

JavaFX Basic Syntax

Packages and Imports

package com.weiqigao.jugdemo;
import java.lang.System as Sys;

Classes

JavaFX has four basic types

 
– String
– Boolean
– Number
– Integer


User can define classes

 
public class Foo { }

Attributes

Classes can have attributes, member functions and member operations

 

public class Foo {
attribute str: String;
attribute boo: Boolean?;
attribute num: Number*;
attribute int: Integer+;
}

Functions and Operations

Classes can have member functions and member operations

 

public class Foo {
public function fun(input:String): String;
public operation opr(input:
Number): Number;
}

Initializers

 

attribute Foo.str = “init”;
function Foo.fun(input) {
return “{input}{input}”;
}
operation Foo.opr(input) {
return 2 * input;
}

Objects
Objects are instantiated with JavaFX object literal notation

 

Foo {
str: “Hi”
boo: true
num: [3.14, 6.28]
int: [1024]
}
Foo {str: “Hi”, int: [9216]}

Variables, Named Instances

 

A variable is introduced by the var keyword
Variable types are inferred from initializer

var str = “Hi”; // String
var nums = [1..10]; // Number*


Named instances are global
INS:Foo = { str: “Hi” };

Double Meaning of var

 

Inside an object literal, var: names the current
instance (odd syntax)

class Foo { attribute bar: Bar; }
class Bar { attribute foo: Foo; }

var foo = Foo {
var: me
bar: Bar { foo: me }
}

Functions

 

function addN(n) {
return function (x) = x + n;
}
println(addN(5)(10));

Operations

 

operation foo(i) {
println(i);
println(i*i);
}
foo(10);

Expressions

 

Relational operators
– ==, <>, <, >, <=, >=
Boolean operators
– and, or, not
Arithmetic operators
– +, -, *, /, %, +=, -=, *=, /=, %=
Other operators
– sizeof, indexof, if/then/else,
select, foreach, new, opr(),
instanceof, this, bind, :, [], format
as, <<>>, {}, (expr), reverse,
[1,3..99]

Statements

 

for (i in [1..3], j in [1..i] where
(i + j) % 2 == 0) {
println(“i: {i}, j: {j}”);
}

Sequences (Arrays)

 

var a = [1, 2, 3, 4, 5, 6, 7];
var i = a[3]; // by index
var j = a[. % 2 == 0]; // [2, 4, 6]
var k = a[indexof . % 2 == 0];
var aa = [a, a]; // flattened
var b = ([] == null); // true
var s = sizeof a; // 7

SynTax By
Weiqi Gao St. Louis Java Users Group July 12, 2007.

Download Doc (Eng Version)