Simple mouse event question
Hi i have a simple question about mouse event.
At the moment i have implemented the MouseListener and the 5 compulsary methods to go along with it.
The method that im interested in for this example is the mouseEntered method.
i have two objects calling to the addMouseListener, a label and a JPanel.
Basically what i want to do is run different code depending on which of the two obove objects the mouse enters.
So far i can write code which will run if either of the two objects gets entered with the mouse however i dont know run code if the label gets entered and run a different code if the JPanel gets entered.
If tried using an if statement within the mouseEntered method ie
if (event.getSource() = "nameOfLabel") //do something
else if (event.getSource() = "nameOfJPanel") //do something else
but it seems the getSource() didnt work.
i dont fancy calling a new Anonymous Class for each of the two objects because that will mean writing out 5 mouse methods twice and i think there must be a far easier/simple way!
thanks for reading.