java - Trying to assign card pictures, but it gives me wrong cards -


i have method:
trying assign picture of card iconcards[][] profiles. pictures located in images/ folder e.g. images/as.gif (ace of spades), images/ad.gif (ace of diamonds) etc.

static void loadcardicons(){     int l =0;     int k =0;      while (k < 14){         (l = 0; l < 4; l++){             string card = "images/" + character.tostring(valueranks[k]) + "c.gif";             iconcards[k][l] = new imageicon(card);             system.out.println(k + " " + l + "   " + card);             card = "images/" + character.tostring(valueranks[k]) + "d.gif";             iconcards[k][l++] = new imageicon(card);             system.out.println(k + " " + l + "   " + card);             card = "images/" + character.tostring(valueranks[k]) + "h.gif";             iconcards[k][l++] = new imageicon(card);             system.out.println(k + " " + l + "   " + card);             card = "images/" + character.tostring(valueranks[k]) + "s.gif";             iconcards[k][l++] = new imageicon(card);             system.out.println(k + " " + l + "   " + card);             k++;         }     }     iconback = new imageicon("images/bk.gif"); }   ...12 3   images/ks.gif 13 0   images/xc.gif 13 1   images/xd.gif 13 2   images/xh.gif 13 3   images/xs.gif  *13 2 images/xs.gif* 

you can see value = 13 , suit = 2. according output above card should images/xh (jokerhearts), prints me xs. why? here's method runs it. can't find out what's going on weeks.

static public icon geticon(card card){     loadcardicons();      return iconcards[valueasint(card)][suitasint(card)]; } 

problem here

iconcards[k][l++] = new imageicon(card); 

l++ post increment operator on l. therefore given l = 0 , k = 0, access

iconcards[0][0] 

and l go 1. might want use pre increment ++l version.

so l (as index iconcards) goes value 2 (for images/xh.gif), not 3 (for images/xs.gif).

see oracle tutorial here on increment/decrement operators explanation on use.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -