I was analyzing a open-source game code and i don’t understand setDefaultSpecialChars() method and setDefaultSmallAlphabet(). These statements fontCharTable[':']=1 + indexOf_Point; and fontCharTable['a'+i] = indexOf_a + i; are new to me.
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class GFont {
public int[] fontCharTable = new int[256];
public void setFontCharTableDefaults(boolean specialChars) {
setDefaultSmallAlphabet(0);
setDefaultBigAlphabet(0);
setDefaultDigits(27);
if (specialChars) {
setDefaultSpecialChars(37);
}
}
public void setDefaultSpecialChars(int indexOf_Point) {
fontCharTable['.']=0 + indexOf_Point;
fontCharTable[':']=1 + indexOf_Point;
fontCharTable[',']=2 + indexOf_Point;
fontCharTable[';']=3 + indexOf_Point;
fontCharTable['?']=4 + indexOf_Point;
fontCharTable['!']=5 + indexOf_Point;
fontCharTable['(']=6 + indexOf_Point;
fontCharTable[')']=7 + indexOf_Point;
fontCharTable['+']=8 + indexOf_Point;
fontCharTable['-']=9 + indexOf_Point;
fontCharTable['*']=10 + indexOf_Point;
fontCharTable['/']=11 + indexOf_Point;
fontCharTable['=']=12 + indexOf_Point;
fontCharTable['\'']=13 + indexOf_Point;
fontCharTable['_']=14 + indexOf_Point;
fontCharTable['\\']=15 + indexOf_Point;
fontCharTable['#']=16 + indexOf_Point;
fontCharTable['[']=17 + indexOf_Point;
fontCharTable[']']=18 + indexOf_Point;
fontCharTable['@']=19 + indexOf_Point;
fontCharTable['ä']=20 + indexOf_Point;
fontCharTable['ö']=21 + indexOf_Point;
fontCharTable['ü']=22 + indexOf_Point;
fontCharTable['Ä']=fontCharTable['ä'];
fontCharTable['Ö']=fontCharTable['ö'];
fontCharTable['Ü']=fontCharTable['ü'];
}
public void setDefaultSmallAlphabet(int indexOf_a) {
for (i=0; i<26; i++) {
fontCharTable['a'+i] = indexOf_a + i;
}
}
}
It’s just a normal array element assignment expression – but using the implicit conversion from
chartoint. So take this:Now consider it as:
Is that now clearer?
Likewise this:
could be written as: