Package com.project.snakeGame
Class GamePanel.MyKeyAdapter
java.lang.Object
java.awt.event.KeyAdapter
com.project.snakeGame.GamePanel.MyKeyAdapter
- All Implemented Interfaces:
KeyListener,EventListener
- Enclosing class:
GamePanel
The
MyKeyAdapter class handles keyboard inputs
to control the snake's direction. It listens for arrow key
presses and updates the snake's direction accordingly.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidListens for key presses and changes the snake's direction based on the arrow keys.Methods inherited from class java.awt.event.KeyAdapter
keyReleased, keyTyped
-
Constructor Details
-
MyKeyAdapter
public MyKeyAdapter()
-
-
Method Details
-
keyPressed
Listens for key presses and changes the snake's direction based on the arrow keys. Prevents the snake from moving in the opposite direction.- Specified by:
keyPressedin interfaceKeyListener- Overrides:
keyPressedin classKeyAdapter- Parameters:
e- TheKeyEventtriggered by the key press.
-