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 TypeMethodDescriptionvoid
Listens 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:
keyPressed
in interfaceKeyListener
- Overrides:
keyPressed
in classKeyAdapter
- Parameters:
e
- TheKeyEvent
triggered by the key press.
-