Game Development Reference
In-Depth Information
to InvinciBagel.java to “reach inside” (think of this as a security breach) to grab these
four Boolean variables. Making these variables
private
prevents this. So, we need to
put .is() and .set() methods into place which force external classes and methods to “re-
quest” this information, using a more “formal” method call.
This time, we are going to use the NetBeans
Generate Getters and Setters
dialog,
which is shown in
Figure 12-2
,
to selectively write the getters (the .is() methods) and
the setters (the .set() methods), which will access the four Boolean variables. Technic-
ally, right now we only need to use the getter .is() methods, so you could use the
Gen-
erate Getter
menu option, shown in the middle (pop-up or floating) Generate
menu, above the selected Getter and Setter option, in the middle (encased with a red
line) of
Figure 12-2
.
I prefer to generate both of these method “directions,” just in case,
later on in the software development process, I need to set these variables (externally,
in another class) for some programming reason relating to the game play logic develop-
ment.
Figure 12-2
.
Use the Source
Insert Code
Getter and Setter dialog to create methods for the four boolean
variables
Select the four Boolean
down
,
left
,
right
, and
up
variables in the Generate Getters
and Setters dialog, shown on the far right side of
Figure 12-2
, click your cursor so that
it is in front of the final } curly brace in your class (this will tell NetBeans that you