Regarding KeyListener: it won't work unless the listened-to component is focusable and has focus. So you will want to call setFocusable(true)
and requestFocusInWindow()
on your JPanel. As for the MouseListener -- something else may be taking the mouse event and preventing it from reaching your JPanel. To debug this you need to post a minimal, compilable, runnable example program.
Also regarding your MouseListener, you're checking getButton()
in a mouseEntered event which makes no sense. The buttons are not involved in this type of event. Are you instead meaning to check mouseDragged(...)
of a MouseMotionListener?