java - how to get element position in 2D array when mouse clicked? -


im building board using gui(may board game). have created 2d array make cells gomoku game. want make function: whenever click cell, cell position displayed.

private cell[][] cells; private in row; private int col;  update: .......  jpanel pn = new jpanel(new gridlayout(row, col, 0, 0)); cells = new cell[row][col]; (int = 0; < size; i++) {         (int j = 0; j < size; j++) {             pn.add(cells[i][j] = new cell());         } ...... private class mouselistener extends mouseadapter {          public void mouseclicked(mouseevent e) {                     (int = 0; < size; i++) {                         (int j = 0; j < size; j++) {                             if (         ) {                                 system.out.println("x: " + + ", y: " + j);                              }                          }                     }             } 

i cant make work although i've tried several times , different conditions in if

you can add mouselistener directly cells , use e.getsource() clicked cell.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -