MenuList.java
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:

J2ME

开发平台:

Java

  1. import javax.microedition.lcdui.*;
  2. class MenuList    extends List    implements CommandListener
  3. {
  4.     private  escapeeMIDlet midlet;
  5.     private Command exitCommand;
  6.     private boolean gameActive = false;
  7.     MenuList(escapeeMIDlet midlet)
  8.     {
  9.         super("逃亡者", List.IMPLICIT);
  10.         this.midlet = midlet;
  11.         append("开始新游戏", null);
  12.         append("高分记录", null);
  13.         append("游戏说明", null);
  14.         exitCommand = new Command("退出", Command.EXIT, 1);
  15.         addCommand(exitCommand);
  16.         
  17.         setCommandListener(this);
  18.     }
  19.     void setGameActive(boolean active)
  20.     {
  21.         if (active && !gameActive)
  22.         {
  23.             gameActive = true;
  24.             insert(0, "继续游戏", null);
  25.         }
  26.         else if (!active && gameActive)
  27.         {
  28.             gameActive = false;
  29.             delete(0);
  30.         }
  31.     }
  32.     public void commandAction(Command c, Displayable d)
  33.     {
  34.         if (c == List.SELECT_COMMAND)
  35.         {
  36.             int index = getSelectedIndex();
  37.             if (index != -1)  // should never be -1
  38.             {
  39.                 if (!gameActive)
  40.                 {
  41.                     index++;
  42.                 }
  43.                 switch (index)
  44.                 {
  45.                 case 0:   // Continue
  46.                     midlet.menuListContinue();
  47.                     break;
  48.                 case 1:   // New game
  49.                     midlet.menuListNewGame();
  50.                     break;
  51.                 case 2:   // High score
  52.                     midlet.menuListHighScore();
  53.                     break;
  54.                 case 3:
  55.                     midlet.menuListInstructions();
  56.                     break;
  57.                 default:
  58.                     // can't happen
  59.                     break;
  60.                 }
  61.             }
  62.         }
  63.         else if (c == exitCommand)
  64.         {
  65.             midlet.menuListQuit();
  66.         }
  67.     }
  68. }