acn wrote:register children's mouseListener inside parent's listener means i should forward my mouseEvent from child to parent, right ?
No.
Every mouse event (in fact, every pointer event) goes through a filtering system. The system asks this:
1) Is the current component concerned in the event (usually through the hitTest() method) ?
2) Does it want it (by looking if any mouse listener is registered for this component) ?
Currently, the component registers themselves as mouse's Listener, so you don't see this. This doesn't mean you can't register any other component's Listener and this is what I'm talking about here.
The code should read:
- Code: Select all
parent::parent()
{
child1 = new WhateverComponent();
addAndMakeVisible(child1);
// Add the child mouse listener to our parent:
addMouseListener(child1, true);
}
What happens from now, is that in parent class you'll receive event for the parent class BUT also those of the child1. AND the child1 will still receive its events too.