You are previewing Beginning Java SE 6 Game Programming, Third Edition.

Beginning Java SE 6 Game Programming, Third Edition

Cover of Beginning Java SE 6 Game Programming, Third Edition by Jonathan S. Harbour Published by Course Technology PTR
  1. Copyright
    1. Dedication
  2. Acknowledgments
  3. About the Author
  4. Introduction
    1. What Will You Learn in This Book?
    2. What about the Programming Language?
    3. What IDE Should You Use?
    4. Conventions Used in This Book
    5. Companion Web Site Downloads
  5. I. Java for Beginners
    1. 1. Getting Started with Java
      1. Java and the Web
      2. The Casual Games Market
      3. Installing and Configuring Java
      4. Your First Java Program
      5. What You Have Learned
      6. Review Questions
      7. On Your Own
    2. 2. Java Programming Essentials
      1. Java Applets and Applications
      2. The Java Language
      3. The Essence of Class
      4. What You Have Learned
      5. Review Questions
      6. On Your Own
    3. 3. Creating Your First Java Game
      1. About the Game Project
      2. Creating the Game
      3. What You Have Learned
      4. Review Questions
      5. On Your Own
  6. II. Java Game Programming
    1. 4. Vector-Based Graphics
      1. Programming Vector Graphics
      2. What You Have Learned
      3. Review Questions
      4. On Your Own
    2. 5. Bitmap-Based Graphics
      1. Programming Bitmapped Graphics
      2. Transparency
      3. What You Have Learned
      4. Review Questions
      5. On Your Own
    3. 6. Simple Sprites
      1. Programming Simple Sprites
      2. Creating a Reusable Sprite Class
      3. What You Have Learned
      4. Review Questions
      5. On Your Own
    4. 7. Sprite Animation
      1. Sprite Animation
      2. What You Have Learned
      3. Review Questions
      4. On Your Own
    5. 8. Keyboard and Mouse Input
      1. Listening to the User
      2. Keyboard Input
      3. Mouse Input
      4. What You Have Learned
      5. Review Questions
      6. On Your Own
    6. 9. Sound Effects and Music
      1. Playing Digital Sample Files
      2. Playing MIDI Sequence Files
      3. Reusable Classes
      4. What You Have Learned
      5. Review Questions
      6. On Your Own
    7. 10. Timing and the Game Loop
      1. The Potency of a Game Loop
      2. Stepping Up to Threads
      3. What You Have Learned
      4. Review Questions
      5. On Your Own
  7. III. The Galactic War Project
    1. 11. Galactic War: From Vectors to Bitmaps
      1. Improving the Game
      2. What You Have Learned
      3. Review Questions
      4. On Your Own
    2. 12. Galactic War: Sprites and Collision Boxes
      1. Creating the Project
      2. What You Have Learned
      3. Review Questions
      4. On Your Own
    3. 13. Galactic War: Squashed by Space Rocks
      1. Being Civilized about Collisions
      2. What You Have Learned
      3. Review Questions
      4. On Your Own
    4. 14. Galactic War: Entity Management
      1. Adjusting to Event-Driven Programming
      2. Enhancing Galactic War
      3. What You Have Learned
      4. Review Questions
      5. On Your Own
    5. 15. Galactic War: Finishing the Game
      1. Let’s Talk about Power-Ups
      2. Enhancing Galactic War
      3. What You Have Learned
      4. Review Questions
      5. On Your Own
    6. 16. Galactic War: Web Deployment
      1. Packaging an Applet in a Java Archive (JAR)
      2. Creating an HTML Host File for Your Applet
      3. What You Have Learned
      4. Review Questions
      5. Epilogue
  8. Chapter Quiz Answers
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
    11. Chapter 11
    12. Chapter 12
    13. Chapter 13
    14. Chapter 14
    15. Chapter 15
    16. Chapter 16
O'Reilly logo

Chapter 8. Keyboard and Mouse Input

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

Listening to the User

Java provides an interesting way to interact with users through a series of listener methods. You ...

The best content for your career. Discover unlimited learning on demand for around $1/day.