KeyListener not reaching my switch statement

前端 未结 1 1281
慢半拍i
慢半拍i 2021-01-20 13:29

I have this code:

    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    imp         


        
相关标签:
1条回答
  • 2021-01-20 14:04

    KeyListener will only fire events if the component it is registered is focusable and has focus.

    JApplet has a JRootPane which adds a JLayeredPane and content pane (amongst other things) ontop of the applet, which may mean that key listener may never be capable of begin notified of events (as other elements are blocking it).

    Instead, use Key Bindings

    0 讨论(0)
提交回复
热议问题