Adding MouseListener breaks Keylistener
When I remove all of the MouseListener components and run the applet I have to click on it to give it focus, then the KeyListener works perfectly. To solve this I added an "opening page" where you have to click on start before the game runs. This would give the applet focus and not start until the player was ready at the same time. I add in the MouseListener and it works great, but now the KeyListener does not register at all. I can not find out why, but I imagine it has something to do with focus again. Anyone know what should be done here?
Code 开发者_开发问答can be found here: http://pastebin.com/LDxtk878
Thanks!
Without examining all 322 lines of your code, you might look at the article How to Write a Key Listener with attention to the section following "Note: To fire keyboard events, a component must have the keyboard focus."
Also, consider extending JApplet
, as an alternative.
精彩评论