Q:

How to get the index of label mouse clicked in JLabel [ ] [ ]?

I've got a two dimension array of JLabel components and I want to get the place where  the mouse clicked in the label like this.
Jlabel [x] [y] // I want this x & y

How should I do that? 
I've tried this but I get nothing!
new MouseAdapter(){
    public void mousePressed(MouseEvent e){
        int a=e.getX();
        int b=e.getY();
        MainBoard.ML.label=MainBoard.disk1[a][b];
        Color c=MainBoard.ML.label.getForeground();
        if(color==1)
            MainBoard.ML.label.setForeground(Color.black);
        else
            MainBoard.ML.label.setForeground(Color.white);
        new Play(a,b,color);
        new Player2(r);
        MainBoard.disk1[a][b].addMouseListener(new ML1(a,b));
    }
};

I want to get the x & y index of the label array. 

A:

Untested and uncompiled code to locate x and y you are seeking is below.
Note that method getX() of class MouseEvent gets the location of the mouse pointer on the computer screen and not the x from your array. Similarly for method getY(). That's why you get nothing.
In the below code I add the same MouseListener to all the JLabels.
The MouseEvent contains the JLabel that the mouse was clicked on and method getSource() of class MouseEvent returns it. Then you need to iterate through your array of JLabels and see which one matches the MouseEvent source.
int rows = // number of rows in 2D array
int cols = // number of cols in 2D array
final JLabel[][] labels = new JLabel[rows][cols]
MouseListener ml = new MouseAdapter() {
    public void mousePressed(MouseEvent me) {
        Object src = me.getSource();
        int x = -1;
        int y = -1;
        for (int i = 0; i < labels.length(); i++) {
            for (int j = 0; j < labels[i].length; j++) {
                if (src == labels[i][j]) {
                    x = i;
                    y = j;
                    break;
                }
            }
            if (x >= 0) {
                break;
            }
        }
        if (x > 0) {
            System.out.printf("JLabel[%d][%d] was clicked.%n", x, y);
        }
        else {
            System.out.println("Could not find clicked label.");
        }
    }
}
for (int row = 0; row < rows; row++) {
    for (int col = 0; col < cols; col++) {
        labels[row][col] = new JLabel(row + "," + col);
        labels[row][col].addMouseListener(ml);
    }
}

