Copyright (C) 2000, 2001, Geert Vernaeve. All Rights Reserved.
package test; import java.awt.*; import java.awt.event.*;
We create a Container containing a Component. Observations: When the Panel gets the mousePressed(), it can receive the following mouseDrag, but the Component cannot! When both Panel and Component listen to mouse moves, only the Component gets them. So it seems that while the mouse button is down, only the receiver of the MousePressed event can listen to the MouseDrags; as soon as we release the button, others van listen to MouseMoves ...
public class AwtMouseTest extends Container implements MouseListener,MouseMotionListener { TestView testview; public AwtMouseTest() { addMouseListener(this); add(testview = new TestView()); setLayout(new FlowLayout()); } public static void main(String [] args) { Frame frame = new Frame("test"); frame.add("Center",new AwtMouseTest()); frame.pack(); frame.show(); } public void mouseReleased(MouseEvent evt) {} public void mouseEntered(MouseEvent evt) {} public void mouseExited(MouseEvent evt) {} public void mousePressed(MouseEvent evt) { System.out.println("Panel mouse pressed"); testview.click(); testview.addMouseMotionListener(this); } public void mouseClicked(MouseEvent evt) {} public void mouseMoved(MouseEvent evt) { System.out.println("Panel move"); } public void mouseDragged(MouseEvent evt) { System.out.println("Panel drag"); } } class TestView extends Component implements MouseMotionListener { public TestView() { } public Dimension getPreferredSize() { return new Dimension(200,200); } public void click() { System.out.println("Component click"); addMouseMotionListener(this); } public void mouseMoved(MouseEvent evt) { System.out.println("Component move"); } public void mouseDragged(MouseEvent evt) { System.out.println("Component drag"); } }