menulist.java
来自「MIDP 2.0 下的一个打飞机的例子,主要是运用了2.0中比1.0多出来的Ga」· Java 代码 · 共 79 行
JAVA
79 行
package hawk;
import javax.microedition.lcdui.*;
class MenuList
extends List
implements CommandListener
{
private HawkMIDlet midlet;
private Command exitCommand;
private boolean gameActive = false;
MenuList(HawkMIDlet midlet)
{
super("Hawk", List.IMPLICIT);
this.midlet = midlet;
append("New game", null);
append("Instructions", null);
exitCommand = new Command("Exit", Command.EXIT, 1);
addCommand(exitCommand);
setCommandListener(this);
}
void setGameActive(boolean active)
{
if (active && !gameActive)
{
gameActive = true;
insert(0, "Continue", 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: // Instructions
midlet.menuListInstructions();
break;
default:
// can't happen
break;
}
}
}
else if (c == exitCommand)
{
midlet.menuListQuit();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?