The keyboard and mouse are the only realistic devices for user input in a Java game, regardless of whether it’s a web-based applet or a standalone application. But even when considering a standard Windows-based game developed in DirectX or another library, the keyboard and mouse are by far the most common forms of user interaction in a game. This chapter covers the important subject of handling user input.
Here are the key topics you will learn in this chapter:
Listening for keyboard events
Testing keyboard input
Displaying key presses
Reading mouse motion
Detecting mouse buttons
Testing mouse input
Java provides an interesting way to interact with users through a series of listener methods. You ...