Creating the Fish
Each Fish object has three methods—a constructor, a swim method that moves the fish, and a drawImage method that draws the fish using the Graphics object you pass it.
The constructor's job is to store what's passed to it—the two fish images, the bounding rectangle of the aquarium, and the object that corresponds to the tank itself. In addition, the constructor creates a random number generator seeded with the current system time in milliseconds (returned by the System.currentTimeMillis method), and it uses this random number generator to create a random location and velocity for the fish. After the random number generator is seeded, every time you call its nextInt method, you'll get a new, random integer from 0 to 232.
Both ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access