I am in the process of refactoring a lot of code for our game to make the object-couplings as nonexistant as possible (for easier testing and future implementations). Currently my JFrame listens for keys, sends it to a eventmanager class, who again needs a reference to every object that performs an action on keyinput and calls a method on those objects.
It seems like a good idea to keep the responsiblity of responding to keyevents within the objects instead, this would for instance allow me to change the current screen and have the new screen behave differently without checking different global states (like switching to a gamemenu).
But I have no idea how to implement a keylistener for my custom objects, it seems it must be a swing/awt component. How would one add a KeyListener to a custom object? I know how to create custom events and custom listeners but don't know how to capture keyboard input via those methods.