java - Netbeans array created in Design view isn't accessible -


i trying create simple minesweeper game (that's user-customizable). in writing it, tried create grid of jbuttons (via jbutton array) using netbeans design view , entering code jpanel:

jbutton mines[] = new jbutton [gridxval*gridyval]; minegrid.setlayout(new java.awt.gridlayout(gridxval,gridyval)); (int = 0 ; < mines.length ; i++)         {             mines [i] = new jbutton(" ");             mines [i].setactioncommand ("" + i);             mines[i].addactionlistener(listener);             //mines [i].setborder (null);             //mines [i].setborderpainted (false);             minegrid.add (mines [i]); } 

later, when access in method via

imageicon icon = new imageicon(minecounter+".png"); mines[a].seticon(icon); 

it gives me error saying, "cannot find symbol". tried configuring jpanel public, i'm still not able edit outside pre-generated code in methods.

this error when click on button trying set image something:

exception in thread "awt-eventqueue-0" java.lang.runtimeexception:     uncompilable source code - erroneous sym type: <any>.seticon     @ gamescreen.clickdraw(gamescreen.java:227)     @ gamescreen$3.actionperformed(gamescreen.java:170) 

any appreciated!

i'm assuming section of code:

minegrid.setlayout(new java.awt.gridlayout(1, 0)); jbutton mines[] = new jbutton [gridxval*gridyval]; minegrid.setlayout(new java.awt.gridlayout(gridxval,gridyval)); (int = 0 ; < mines.length ; i++) {     mines [i] = new jbutton(" ");     mines [i].setactioncommand ("" + i);     mines[i].addactionlistener(listener);     //mines [i].setborder (null);     //mines [i].setborderpainted (false);     minegrid.add (mines [i]); } 

was entered manually through 1 of "code" editing options in netbeans.

you need take jbutton mines[] = new jbutton [gridxval*gridyval]; , declare @ class level , modify "custom code" initialise variable...

private jbutton mines[];  private void initcomponents() {     //...     minegrid.setlayout(new java.awt.gridlayout(1, 0));     jbutton mines[] = new jbutton [gridxval*gridyval];     minegrid.setlayout(new java.awt.gridlayout(gridxval,gridyval));     (int = 0 ; < mines.length ; i++)     {         mines [i] = new jbutton(" ");         mines [i].setactioncommand ("" + i);         mines[i].addactionlistener(listener);         //mines [i].setborder (null);         //mines [i].setborderpainted (false);         minegrid.add (mines [i]);     }     //... }// </editor-fold>       

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -