I have throught that maybe because this is extending gamecanvas,and not canvas, but then what should I do?
I would prefer to just use my checkKeys method, and getKeyState to read user input.
public void checkKeys(int iKey, long currTick){
long elapsedTick = 0;
//loop through the keys
for (int i = 0; i < 12; i++){
// by default, key not pressed by user
isDown[i] = false;
// is user pressing the key
if ((iKey & wholeKeyValue[i]) != 0){
elapsedTick = currTick - keyTick[i];
//is it time to toggle key state?
if (elapsedTick >= keyDelay){
// save the current time
keyTick[i] = currTick;
// toggle the state to down or pressed
isDown[i] = true;
}
}
}
}
public void keyPressed(int keyCode){
vect.addElement(getKeyName(keyCode));
//this.repaint();
}//end keyPressed
public void option0(){
int xFontPos = 50;
long lCurrTick = 0; // current system time in milliseconds;
int iKey = 0;
boolean option0isRunning = true;
//loadFont();
//Vector vect = new Vector();
while(option0isRunning){
lCurrTick = System.currentTimeMillis();
//iKey = getKeyStates();
iKey = getKeyStates();
//xFontPos ++;
checkKeys(iKey, lCurrTick);
if(isDown[fireKey]){
//unLoadFont();
vect.removeAllElements();
option0isRunning = false;
return;
}
//restore the clipping rectangle to full screen
g.setClip(0, 0, getWidth(), getHeight());
//set drawing color to black
g.setColor(0x000000);
//fill the whole screen
g.fillRect(0, 0, getWidth(), getHeight());
// set drawing color to white
g.setColor(0xffffff);
//display the key code last pressed
String keyData = null;
int fontHeight = g.getFont().getHeight();
//Number of lines of text that fit on screen.
int cntLimit = this.getHeight()/fontHeight;
int yOffset = 0;
int xOffset = 0;
for(int cnt = 0;cnt < vect.size();cnt++){
keyData = (String)vect.elementAt(cnt);//note cast
if(cnt * fontHeight < this.getHeight() - fontHeight){
//Display in first column.
yOffset = cnt * fontHeight;
xOffset = 5;
}else{
//Display in second column
yOffset = (cnt - cntLimit) * fontHeight;
xOffset = this.getWidth()/2;
}//end else
//Draw the string on the Canvas.
g.drawString(keyData,xOffset,yOffset,0);
}//end for loop
flushGraphics();
try{
Thread.sleep(30);
} catch (Exception ex){
}
}
}

New Topic/Question
Reply


MultiQuote



|