How to access boolean array Java -


i have following constructor defines board , checks if of 3 jbuttons have been clicked:

timer timer = new timer(500, this);  private boolean[][] board; private boolean isactive = true; private int height; private int width; private int multiplier = 40;  jbutton button1; jbutton button2; jbutton button3; public board(boolean[][] board) {     this.board = board;     height = board.length;     width = board[0].length;     setbackground(color.black);     button1 = new jbutton("stop");     add(button1);     button1.addactionlistener(new actionlistener() {         public void actionperformed(actionevent e) {             isactive = !isactive;             button1.settext(isactive ? "stop" : "start");         }     });     button2 = new jbutton("random");     add(button2);     button2.addactionlistener(new actionlistener() {         public void actionperformed(actionevent e) {             this.board = randomboard();         }     });     button3 = new jbutton("clear");     add(button3);     button3.addactionlistener(new actionlistener() {         public void actionperformed(actionevent e) {             this.board = clearboard();         }     }); } 

but returns error:

exception in thread "main" java.lang.error: unresolved compilation problems:      board cannot resolved or not field     board cannot resolved or not field 

why this? how access this.board in constructor?

the problem caused trying access this.board inside anonymous inner classes. since there no board field defined, causes error.

for example this:

button2.addactionlistener(new actionlistener() {     public void actionperformed(actionevent e) {         this.board = randomboard();     } }); 

in order able use board variable inside anonymous inner classes either need remove this or use board.this.board (if want more explicit).


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -