⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainmenu.java

📁 孤单惊魂
💻 JAVA
字号:
import javax.microedition.lcdui.*;public class MainMenu    extends Canvas implements CommandListener {  private int SCREEN_WIDTH = getWidth();  private int SCREEN_HEIGHT = getHeight();  private int N = 7, menuindex = 0;  private String menustr[] = new String[N];  private Image button1, button2;  private static Displayable instance;  synchronized public static Displayable getInstance() {    if (instance == null) {      instance = new MainMenu();    }    return instance;  }  private MainMenu() {    menustr[0] = "新游戏";    menustr[1] = "载入游戏";    menustr[2] = "玩家积分";    menustr[3] = "设置";    menustr[4] = "帮助";    menustr[5] = "关于";    menustr[6] = "退出";    try {      button1 = Image.createImage("/button1.png");      button2 = Image.createImage("/button2.png");    }    catch (Exception ex) {}    addCommand(new Command("确定", Command.OK, 1));    setCommandListener(this);  }  protected void keyPressed(int key) {    if (menuindex < N) {      switch (getGameAction(key)) {        case Canvas.UP:          menuindex--;          if (menuindex < 0) {            menuindex = N - 1;          }          break;        case Canvas.DOWN:          menuindex++;          if (menuindex > (N - 1)) {            menuindex = 0;          }          break;      }      repaint();    }  }  protected void paint(Graphics g) {    g.setColor(74, 50, 0);    g.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);    g.setColor(200, 10, 0);    g.setFont(Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD,                           Font.SIZE_LARGE));    g.drawString("孤 胆 惊 魂", SCREEN_WIDTH / 2,1,                 Graphics.HCENTER | Graphics.TOP);    g.setFont(Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD,                           Font.SIZE_MEDIUM));    for (int i = 0; i < N; i++) {      if (i == menuindex) {        g.drawImage(button2, this.getWidth() / 2,                    this.getHeight() / 9 * (1 + i),                    Graphics.HCENTER | Graphics.TOP);        g.setColor(255, 0, 0);      }      else {        g.drawImage(button1, this.getWidth() / 2,                    this.getHeight() / 9 * (1 + i),                    Graphics.HCENTER | Graphics.TOP);        g.setColor(255, 255, 255);      }      g.drawString(menustr[i], this.getWidth() / 2,                   this.getHeight() / 9 * (1 + i),                   Graphics.HCENTER | Graphics.TOP);    }  }  public void commandAction(Command c, Displayable s) {    String cmd = String.valueOf(menuindex);    Navigator.flow(cmd);  }}

⌨️ 快捷键说明

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