It is not recognized because you are implementing mouseDraggedinternally addMouseListener.
mouseDraggedstarts and starts with . MouseMotionListenermousePressed MouseListener
Therefore, you need to implement both MouseListener, MouseMotionListenerand accordingly add the correct listener.
public class MyClass extends JPanel implements MouseListener,
MouseMotionListener {
public MyClass() {
this.addMouseListener(this);
this.addMouseMotionListener(this);
}
public void mousePressed(MouseEvent e) { ... }
public void mouseDragged(MouseEvent e) { ... }
}
source
share