java - Updating Jframe based on JLabel Click -


i making "super tic-tac-toe" application in java. here description of aiming for. http://mathwithbaddrawings.com/ultimate-tic-tac-toe-original-post. having problems updating jframe on click. application made of individual cells (jlabels) make tic-tac-toe boards (jpanels) reside in jframe.

my problem using getsource on mouseclick me seep jpanel, , cannot access cell of tic-tac-toe grid pressed. there way check 1 pressed current method of organizing project?

here code viewing tictactoe board contains listener:

public class tictactoeview extends jpanel {     public cellview[][] cv;     public tictactoe ttt;     public tictactoeview(tictactoe t) {         int rows = 3;         int columns = 3;         cv = new cellview[3][3];         ttt = t;          setsize(3 * 64, 3 * 64);         setbackground(color.white);         setlayout(new gridlayout(rows, columns));         setvisible(true);         setfocusable(true);         (int = 0; < 3; i++) {             (int j = 0; j < 3; j ++) {                 system.out.println(ttt.getcellat(i, j).tostring());                 cv[i][j] = new cellview(ttt.getcellat(i, j));                 cv[i][j].addmouselistener(new yourlistener());                 add(cv[i][j]);             }         }          setvisible(true);     }      public string tostring() {         return ttt.tostring();     }      public class yourlistener extends mouseadapter{          public void mouseclicked(mouseevent e){              cellview labelreference=(cellview)e.getsource();             cell cellclicked = labelreference.getcell();              system.out.println(cellclicked.getcol() +"," + cellclicked.getrow());             cellclicked.setstate(cellstate.o);             ttt.setcellat(cellclicked.getcol(), cellclicked.getrow(), cellstate.o);             system.out.println(ttt.tostring());         }     } } 

right when system.out changes correct cell o expected. don't know how update frame here gameframe made out of this.

first of all, stop using separate class mouselistener, source of problem. directly add mouse listener cv[i][j]. able update frame because mouse listener in same class.

cheers.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -