Can I add an abstract class as a KeyListener?

Sure. This is what my keyPressed method looks like.


public void keyPresssd(KeyEvent e)
{
         switch (e.getKeyCode())
         {
               case KeyEvent.VK_ESCAPE:
                      keyboard[KEY_ESC] = true;
               case KeyEvent.VK_ENTER:
                      keyboard[KEY_ENTER] = true;
               ...
          }
}

That’s the basic idea. The KEY variables are my own constants.

By the way, what is dependency injection?

Why do you have your own constants?

Just a simple luxury so I don’t need to import or specify java.awt.event.KeyEvent.

I have been comfort with DI on java2d back then. On OP’s case I will use an interface that take boolean arrays of key input to be implemented for class that need it.

He he, yeah, I think I’m following the basic idea, but I need more information:

  1. You are writing about a “lag”. How do you measure it, and how does it show itself?
  2. How often are you polling the boolean array, and how are you doing this (ex. a while-loop with a sleep??) ?

Cheers :-).
/Morten