menulist.java

来自「用 Jbulider 写的 是男人就撑20秒 希望大家能够喜欢」· Java 代码 · 共 77 行

JAVA
77
字号
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();
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?