📄 keyaction2.java
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class keyAction2 extends MIDlet implements CommandListener
{
Display display;
Form form;
Command okCommand;
Command exitCommand;
canvasKey canvaskey;
public keyAction2()
{
canvaskey=new canvasKey();
display=Display.getDisplay(this);
form=new Form("Form游戏按键控制");
okCommand = new Command("确认", Command.OK, 2);
exitCommand = new Command("离开", Command.EXIT, 2);
form.append("测试游戏按键控制");
form.addCommand(okCommand);
form.addCommand(exitCommand);
form.setCommandListener(this);
}
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp(){}
public void destroyApp(boolean unconditional){}
public void commandAction(Command cmd, Displayable disp)
{
if (cmd == okCommand)
{
display.setCurrent(canvaskey);
}
else if(cmd == exitCommand){
destroyApp(false);
notifyDestroyed();
}
}
class canvasKey extends Canvas
{
String keyname="";
int gameaction=0;
Image handImage;
Image keyImage;
String[] maxString={"UP", "SOFT1", "LEFT", "SELECT", "RIGHT", "SOFT2", "DOWN",
"SEND", "CLEAR", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"ASTERISK","0","POUND"
};
int[] maxisX={85, 40, 60, 85, 110, 130, 85,
30, 85, 35, 85, 135, 35, 85,
135, 35, 85, 135, 35, 85, 135
};
int[] maxisY={48, 55, 55, 55, 55, 55, 65,
70, 85, 95, 105, 95, 115, 125,
115, 135, 145, 135, 155, 165, 155
};
public canvasKey()
{
try{
handImage=Image.createImage("/hand.png");
keyImage=Image.createImage("/key.png");
}catch(Exception ex){}
}
public void keyPressed(int keyCode)
{
keyname=getKeyName(keyCode);
gameaction=getGameAction(keyCode);
repaint();
}
public void paint(Graphics g)
{
g.setColor(0xffffff);
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(0);
g.drawString("游戏按键对照表", 40, 1, Graphics.LEFT | Graphics.TOP);
g.drawString("按键名称为:"+keyname, 50, 13, Graphics.LEFT | Graphics.TOP);
g.drawString("游戏按键码:"+String.valueOf(gameaction), 50, 25, Graphics.LEFT | Graphics.TOP);
g.drawImage(keyImage, 15, 40,Graphics.LEFT | Graphics.TOP);
for(int i=0; i<maxString.length;i++)
if(maxString[i].equals(keyname))
g.drawImage(handImage, maxisX[i], maxisY[i], Graphics.LEFT | Graphics.TOP);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -