Hi. I'm making a minesweeper game and I'm trying to assign icons to each button for when they're pressed, but for some reason they don't show up after I press them. I'll just post the code here.
private void setButtonValues(int iRows, int iCols) { for (int i = 0 ; i < iRows ; i++ ) for (int j = 0 ; j < iCols ; j++ ) if ( buttons[i][j].getDisabledIcon() != mine ) switch(addValues(i , j)) { case 0: buttons[i][j].setDisabledIcon(null); break; case 1: buttons[i][j].setDisabledIcon(value1); break; case 2: buttons[i][j].setDisabledIcon(value2); break; case 3: buttons[i][j].setDisabledIcon(value3); break; case 4: buttons[i][j].setDisabledIcon(value4); break; } } private int addValues(int iRow, int iCol) { int surroundingMines = 0; for (int i = -1 ; i <= 1 ; i++ ) for ( int j = -1 ; j <= 1 ; j++ ) if(notOutOfBounds(iRow + i, iCol + j) && (i!= 0 || j != 0)) { if(buttons[iRow + i][iCol + j].getDisabledIcon() == mine) surroundingMines++; } return surroundingMines; }
What this does is basically scan the buttons around and check how many mines there are and give the final value which is assigned by adding a picture with the corresponding number on it. For some reason they don't appear when I press the button, even though I know they are assigned since I have this in the event handler:
if(b.getDisabledIcon()== BoardPanel.getMine()) JOptionPane.showMessageDialog(null, "You lost!");
Which actually works and lets me know when I've clicked a mine, even if it doesn't display the picture. What am I missing? Is there another method for this?
Thank you!