I am developing an application in which I have two JPanels (aPanel and bPanel) added to a parent JPanel (cPanel). I need to be able to double click on either aPanel or bPanel to change its color. If I double click on aPanel, it changes color as desired. When I double click on bPanel, its color does not change but aPanel's does. I have tried using the following methods to ID the panels: contains(), getComponentAt() and findComponentAt() but all give the same undesired behavior. I hope someone can point me in the right direction. The relevant code section is provided. (The code compiles but the "beep" never executes)
if(aPanel.findComponentAt(me.getX(), me.getY())==aPanel){
aPanel.setBackground(chosenColor);
}
else if(bPanel.findComponentAt(me.getX(), me.getY())==bPanel){
Toolkit.getDefaultToolkit().beep(); //to test if this is being executed
bPanel.setBackground(chosenColor);
}
The "me" comes from public void mouseClicked(MouseEvent me), and another section of the code that uses "me" is working fine.