📄 manmidlet.java
字号:
package man;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
/**
* MIDlet 应用主单元
*/
public class ManMIDlet
extends MIDlet implements CommandListener {
//--- 定义变量 ----------------------------------------------------------------
private Display display; // 显示对象
private ManGameCanvas manGC; // 主类对象
private Command exitCommand; // 退出按键
private Command confirmCommand; // 确定对象
private List list; // 难度列表对象
private String[] position = { // 难度名
"普通", "噩梦", "地狱","重置游戏记录"};
private Image[] positionicon = { // 难度图标
ImageTools.getImage("/pic/d_easy.png"),
ImageTools.getImage("/pic/d_normal.png"),
ImageTools.getImage("/pic/d_hard.png"),
ImageTools.getImage("/pic/record.png")};
private Image ImgAlert=ImageTools.getImage("/pic/alert.png");
private Alert alert; // 警告
//--- 应用主方法 --------------------------------------------------------------
public ManMIDlet() {
manGC = new ManGameCanvas(this);
display = Display.getDisplay(this);
exitCommand = new Command("退出", Command.EXIT, 1);
confirmCommand = new Command("确定", Command.SCREEN, 1);
}
//--- 开始 -------------------------------------------------------------------
protected void startApp() {
alert=new Alert(null,null,ImgAlert,AlertType.WARNING);
alert.setTimeout(3000);
list = new List("选择难度", List.EXCLUSIVE, position, positionicon);
list.addCommand(exitCommand);
list.addCommand(confirmCommand);
list.setCommandListener(this);
display.setCurrent(list);
}
protected void pauseApp() {
}
protected void destroyApp(boolean unconditional) {
}
//--- 退出 -------------------------------------------------------------------
protected void quitApp() {
System.gc();
destroyApp(true);
notifyDestroyed();
}
//--- 监听按钮 ----------------------------------------------------------------
public void commandAction(Command command, Displayable displayable) {
if (command == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
if (command == confirmCommand) {
int gamelevel = list.getSelectedIndex();
if(gamelevel==3){
display.setCurrent(alert);
manGC.resetrecord(1);
manGC.resetrecord(2);
manGC.resetrecord(3);
}
else if(gamelevel<3){
manGC.setGameLevel(gamelevel + 1);
display.setCurrent(manGC);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -