Java Reference
In-Depth Information
Class Declaration
To declare a class in JavaFX, use the class keyword.
public class Title {
}
Developer Note: By convention, the first letter of class names is capitalized.
The public keyword is called an access modifier and means that this class can
be used by any other class or script, even if that class is declared in another script
file. If the class does not have a modifier, it is only accessible within the script
file where it is declared. For example, the class Point in Listing 3.2 does not
have a visibility modifier, so it is only has script visibility and can only be used
within the ArtWork script.
Listing 3.2
Artwork.fx
class Point {// private class only
//visible to the ArtWork class
var x:Number;
var y:Number;
}
public class ArtWork {
var location: Point;
}
Developer Note: For each JavaFX script file, there is a class generated using
that script filename, even if one is not explicitly defined. For example, in the previ-
ous example for ArtWork.fx , there is a class ArtWork . This is true even if we had
not included the public class ArtWork declaration.
Also, all other classes defined within the script file have their name prepended with
the script file's name. For example, in the previous example, class Point is fully quali-
fied as ArtWork.Point . Of course, if ArtWork belongs to a package, the package name
would also be used to qualify the name. For example, com.acme.ArtWork.Point .
To extend a class, use the extends keyword followed by the more generalized
class name. JavaFX classes can extend at most one Java or JavaFX class. If you
extend a Java class, that class must have a default (no-args) constructor.
 
 
Search WWH ::




Custom Search