Java Reference
In-Depth Information
Listing 3.5
Script and Instance Variables
import javafx.scene.Cursor;
import javafx.scene.paint.Color;
// import of script variable from javafx.scene.Cursor
import javafx.scene.Cursor.CROSSHAIR;
// Unchangeable script variable
def defaultText = "Replace ME"; // Script accessible only
// Changeable script variable
public var instanceCount: Integer; // Public accessible
public class Title {
// Unchangeable instance variables
def defStroke = Color.NAVY; // class only access,
//resolves to javafx.scene.paint.Color.NAVY
// Changeable instance variables
// defaults to the empty String ""
public var text:String;
public var width: Number; // defaults to zero (0.0)
public var height = 100; // Infers Integer type
public var stroke: Color = defaultStroke ;
public var strokeWidth = 1.0; // Infers Number type
public var cursor = CROSSHAIR;
//resolves to javafx.scene.Cursor.CROSSHAIR
...
}
You may have noticed that some of the declarations contain a type and some
don't. When a type is not declared, the type is inferred from the first assigned
value. String , Number , Integer , and Boolean are built-in types, everything else
is either a JavaFX or a Java class. (There is a special syntax for easily declaring
Duration and KeyFrame class instances that will be discussed in Chapter 7, Add
Motion with JavaFX Animation.)
Table 3.1 lists the access modifiers for variables and their meaning and restric-
tions. You will notice reference to initialization, which refers to object literal
declarations. Also, you will notice variables being bound. This is a key feature of
JavaFX and is discussed in depth in Chapter 4 .
 
Search WWH ::




Custom Search