问题
I'm building a 2d game in Java and I decided to use Canvas on which I would display the images relevant to the current frame. I'm using Canvas because I've heard it is more efficient in terms of time than JPanel. Is it true?
Also, I would like to add some input to the game through key bindings since key listeners could cause focus issues and are lower level construct: keylistener not working after clicking button (see answer). Is there a way to use key bindings with a Canvas? Or I would simply use KeyListener.
回答1:
you can't add KeyBindings to awt.Canvas, there isn't method implemented in API
you can to add only KeyListener
change your decision and to use JPanel/JComponent
来源:https://stackoverflow.com/questions/19211932/canvas-and-inputmap