📄 btgame.java
字号:
package bluetoochgame;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class BTGame extends MIDlet implements CommandListener{
private static BTGame instance;
private MyCanvas mycanvas ;
private ChoiceGroup choices;
private Form initForm;
/** 构造函数 */
public BTGame() {
instance = this;
}
public void startApp() {
initForm = new Form("Connect 4");
String[] peerNames = { "Server", "Client" };
choices = new ChoiceGroup("Please select peer type:", Choice.EXCLUSIVE, peerNames, null);
initForm.append(choices);
Command exitCommand = new Command("Exit", Command.EXIT, 0);
initForm.addCommand(exitCommand);
Command playCommand = new Command("Play", Command.OK, 0);
initForm.addCommand(playCommand);
initForm.setCommandListener(this);
Display.getDisplay(this).setCurrent(initForm);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public static void quitApp() {
instance.destroyApp(true);
instance.notifyDestroyed();
instance = null;
}
public void commandAction(Command c, Displayable s) {
if (c.getCommandType() == Command.EXIT) {
destroyApp(true);
notifyDestroyed();
}
else if (c.getCommandType() == Command.OK) {
String name = choices.getString(choices.getSelectedIndex());
if (mycanvas == null) {
mycanvas = new MyCanvas(Display.getDisplay(this), name);
Command exitCommand = new Command("Exit", Command.EXIT, 0);
mycanvas.addCommand(exitCommand);
mycanvas.setCommandListener(this);
mycanvas.start();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -