私の目標は、このコードを簡素化することでした (すべて正常に動作します)。
package test;
import java.awt.Window;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JWindow;
public class A extends JWindow implements MouseListener, MouseMotionListener {
public A() {
addMouseListener(A.this);
addMouseMotionListener(A.this);
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
//This method is being used, working fine
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseDragged(MouseEvent e) {
//This method is being used, working fine
}
@Override
public void mouseMoved(MouseEvent e) {
}
}
しかし、次MouseAdapter
のように使用することにした場合:
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
transferFocusBackward();
//This method is being used, working fine
}
@Override
public void mouseDragged(MouseEvent e) {
//This method is being used, not working anymore
}
});
mouseDragged
イベントを受信しません。しかし、次のように追加するMouseMotionListener
と:
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
//This method is being used, working fine
}
});
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
//This method is being used, working fine
}
});
その後、すべてが正常に戻ります。だから私の質問は - mouseDragged
、mouseMoved
およびクラスのmouseWheelMoved
メソッドがMouseAdapter
機能しない場合の目的は何ですか?