An action listener is used to listen for action events. The button starts the action when it is pressed and released with the mouse (and not when pressed) or when pressed from the keyboard (space, mnemonics, keyboard shortcuts, etc.). This is a high level event. A mouse click is a lower level event that is handled by MouseListener
.
Add MouseListener to your JPanel if you want to handle mouse clicks.
source share