Game Development Reference
In-Depth Information
Figure 17-27
.
Use a .toBack() method call in the gameButton code, and .toFront() method call in the other Button
code
Using Random Number Generators:
java.util.Random
The
java.util
package contains programming
utilities
that you can use for your Java 8
games development, as you may have guessed from the package name. One of the
most important Java utilities for game programmers is the
Random
class, and its
Ran-
dom()
constructor method. This class can be used to create
Random Number Gener-
ator
objects, which generate random number (or boolean) values for use inside your
game programming logic. We will be using this class to generate both
int
(integer, for
random screen locations) and
boolean
(for “guess where the Enemy is coming from
next” functions) random values. These will make sure the game player cannot anticip-
ate the game by recognizing
patterns
during the game play. The Java 8 Random class