If your labels are added a to a container ( like a JPanel ) you can add a listener to this container and know which component is at certain location.
JPanel panel = new JPanel();
panel.addMouseListener( whichOneListener );
f.setContentPane( panel );
In this case I use a mouseListener because that give me the location where the user clicked.
private static MouseListener whichOneListener = new MouseAdapter() {
public void mouseClicked( MouseEvent e ) {
JComponent c = ( JComponent ) e.getSource();
JLabel l = ( JLabel ) c.getComponentAt( e.getPoint() );
System.out.println( l.getText() );
}
};
And prints correctly what component was clicked.
The full source code is here