Why not cast the reference returned by getSource() to the component's class that created the event and call its method directly.
Type: Posts; User: Norm
Why not cast the reference returned by getSource() to the component's class that created the event and call its method directly.
Look at the API doc for the event object that is passed to the mouse listener methods. If you can get a reference to the component that created the mouse event, you could call its methods.
For a...
If the squares are components, the event object passed to the listener method could have a reference to it.
Look at the getSource() method.
After the call to setBackground you'll probably need to call repaint() to have the new color shown.
Please post the full text of the compiler's error messages.
On which component(s) do you want the mouse's movements detected? Add the listener to that/those component(s).