Game Development Reference
In-Depth Information
constants, and user interface element scaling settings. If you are looking for an under-
standing regarding the concept of static, it can be thought of as fixed, or not capable of
being changed. A photograph is a static image, whereas video is not static. We'll look
at this concept often during this topic.
A nested class uses what is commonly referred to in Java as dot notation to refer-
ence the nested class “off of” its master, or parent, containing class. For instance,
MasterClass.NestedClass would be the referencing format that would be used to ref-
erence a nested class via its master class (containing class) name, using generic class
type names here. If you created an InvinciBagel SplashScreen nested class to draw the
splash screen for your Java game, it would be referenced in your Java code as Invin-
ciBagel.SplashScreen , using this Java 8 dot notation syntax.
Let's take a look at, for example, the JavaFX Application class, which contains a
Parameters nested class. This nested class encapsulates , or contains, the parameters
that you can set for your JavaFX application. Thus, this Application.Parameters nes-
ted class would be a part of the same javafx.application package as your Application
class and would be referenced as javafx.application.Application.Parameters , if you
were using an import statement.
Similarly, the constructor method would be written as Application.Parameters() ,
because the constructor method must have the exact same naming schema as the class
that it is contained in. Unless you are writing code for other developers, which is when
nested classes are most often used (such as the JavaFX Application class or the many
nested utility or constant provider classes which you will find in the Android OS), you
are far more likely to utilize non-static nested classes (commonly referred to as Java in-
ner classes ).
A nested class can be declared by using the Java static keyword. A Java keyword is
also sometimes called a Java modifier. Therefore, if you were to do an InvinciBa-
gel.SplashScreen nested class, the InvinciBagel class and its
SplashScreen nested class declaration (Java 8 programming structure) would look
something like this:
public class InvinciBagel extends Application {
static class SplashScreen {
// The Java code that creates and displays your
splashscreen is in here
}
}
Search WWH ::




Custom Search