Java Reference
In-Depth Information
var vehicle = Vehicle {
year:2010
color: "Grey"
make:"Mini"
model:"Cooper"
};
vehicle.drive();
4. Save the file as Vehicle.fx . Now, from the command-line, compile it with
$> javafxc Vehicle.fx
If you are using an IDE, you can simply right, click on the
file to run it.
When the code executes, you should see:
$> You are driving a 2010 Grey Mini Cooper!
How it works...
The previous snippet shows how to declare a class in JavaFX. Albeit a simple class, it shows
the basic structure of a JavaFX class. It has properties represented by variables declarations:
var make;
var model;
var color;
var year;
and it has a function:
function drive () : Void {
println("You are driving a "
"{year} {color} {make} {model}!")
}
which can update the properties and/or modify the behavior (for details on JavaFX functions,
see the recipe Creating and Using JavaFX functions ). In this example, when the function is
invoked on a vehicle object, it causes the object to display information about the vehicle
on the console prompt.
 
Search WWH ::




Custom Search