JPanel not responding to keylistener

后端 未结 2 1170
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-24 11:57

I tried to make a JPanel that would display how many times you press each navigation key, but it is only displaying 4 zeros.

//In the keyPressed() method, I put the foll

2条回答
  •  庸人自扰
    2021-01-24 12:19

    • Call repaint(); in keyPressed() method in the end.

    • Call count_keys.setFocusable(true); in main method just below its creation

    Because JPanel is not focus able hence KeyListener is not working.

提交回复
热议问题