MenuList.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:
J2ME
开发平台:
Java
- import javax.microedition.lcdui.*;
- class MenuList extends List implements CommandListener
- {
- private escapeeMIDlet midlet;
- private Command exitCommand;
- private boolean gameActive = false;
- MenuList(escapeeMIDlet midlet)
- {
- super("逃亡者", List.IMPLICIT);
- this.midlet = midlet;
- append("开始新游戏", null);
- append("高分记录", null);
- append("游戏说明", null);
- exitCommand = new Command("退出", Command.EXIT, 1);
- addCommand(exitCommand);
- setCommandListener(this);
- }
- void setGameActive(boolean active)
- {
- if (active && !gameActive)
- {
- gameActive = true;
- insert(0, "继续游戏", null);
- }
- else if (!active && gameActive)
- {
- gameActive = false;
- delete(0);
- }
- }
- public void commandAction(Command c, Displayable d)
- {
- if (c == List.SELECT_COMMAND)
- {
- int index = getSelectedIndex();
- if (index != -1) // should never be -1
- {
- if (!gameActive)
- {
- index++;
- }
- switch (index)
- {
- case 0: // Continue
- midlet.menuListContinue();
- break;
- case 1: // New game
- midlet.menuListNewGame();
- break;
- case 2: // High score
- midlet.menuListHighScore();
- break;
- case 3:
- midlet.menuListInstructions();
- break;
- default:
- // can't happen
- break;
- }
- }
- }
- else if (c == exitCommand)
- {
- midlet.menuListQuit();
- }
- }
- }