Game Development Reference
In-Depth Information
Note It is possible to use, instead of the Java import keyword, the fully qualified
class name, that is, to preface the class name with the package name, right inside your
Java code. Convention dictates using the import statement; however, line 20 in Figure
3-2 could be written as javafx.scene.control.Button btn = new
javafx.scene.control.Button(); if you wanted to buck standard Java pro-
gramming convention.
Java Classes: Logical Java Constructs to
Build On
The next logical Java programming construct beneath the package level is the Java
class level, as you saw in the import statement, which references both the package that
contains the class and a class itself. Just as a package organizes all the related classes,
so too a class organizes all its related methods, variables, and constants and, some-
times, other nested classes.
Thus, the Java class is used to organize your Java code at the next logical level of
functional organization, and so your class will contain Java code constructs that add
functionality to your application. These may include methods, variables, constants,
nested classes, or inner classes.
Java classes can also be used to create Java objects . Java objects are constructed ,
using your Java class, and have the same name as the Java class and as that class's con-
structor method .
As you saw in Figure 3-2 , you declare your class, using a Java class keyword,
along with a name for your class. You can also preface the declaration with Java modi-
fier keywords, which you will be studying later in this chapter (see the section “Java
Modifier Keywords: Access Control and More”). Java modifier keywords are always
placed before (or in front of) the Java class keyword, using the following format:
<modifier keywords> class <your custom classname goes
here>
One of the powerful features of Java classes is that they can be used to modularize
your Java game code so that your core game application features can be a part of a
high-level class that can be subclassed to create more specialized versions of that
class. Once a class has been subclassed, it becomes a superclass , in Java class hier-
Search WWH ::




Custom Search