How to use KeyListener with JFrame?

后端 未结 4 1740
萌比男神i
萌比男神i 2020-11-30 14:42

So, I was trying to make a rectangle move with a KeyEvent (KeyListener) and whenever I try to hit the key, the rectangle doesn\'t move.

The

4条回答
  •  忘掉有多难
    2020-11-30 15:36

    You should add your listener in the mainDraw class, not your mainFrame.

    It's a good practice not to handle key and mouse events in Frames and Windows.

    o/

提交回复
热议问题