btgame.java
来自「Java ME手机应用开发大全一书的配套光盘上的源码」· Java 代码 · 共 62 行
JAVA
62 行
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 + =
减小字号Ctrl + -
显示快捷键?