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

📄 recorddbmidlet.java

📁 《J2ME无线移动游戏开发》一书的配套光盘
💻 JAVA
字号:
package ch12;

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class RecordDBMIDlet
    extends MIDlet
    implements CommandListener {

  //声明一个Display对象
  private Display aDisplay;

  //声明一个构成菜单的列表List对象
  private List aList;

  //声明一个显示记录的列表List对象
  private List recordList;

  //声明一个退出按钮Command对象
  private Command exitCommand;

  //声明一个确认按钮Command对象
  private Command okCommand;

  //声明一个查找窗体
  private Form searchForm;

  //声明一个添加窗体
  private Form addForm;

  //声明一个信息提示框
  private Alert anAlert;

  /*
   1.构造器
   */
  public RecordDBMIDlet() {
    aList = new List(null, Choice.IMPLICIT);
    aList.setTitle("排行榜");
    aList.append("添加", loadImage("/icons/rankrecord/star.png"));
    aList.append("按姓名排列", loadImage("/icons/rankrecord/star.png"));
    aList.append("按ID号码排列", loadImage("/icons/rankrecord/star.png"));
    aList.append("按姓名查询", loadImage("/icons/rankrecord/star.png"));
    aList.append("按ID号查询", loadImage("/icons/rankrecord/star.png"));

    exitCommand = new Command("退出", Command.EXIT, 1); //
    okCommand = new Command("确认", Command.OK, 1);
    aList.addCommand(exitCommand);
    aList.addCommand(okCommand);
    aList.setCommandListener(this);
  }

  /*
    2.启动应用程序
   */
  public void startApp() {
    anAlert = new Alert("积分排行榜", "          Rights Reserved!by 施铮",
                        loadImage("/icons/rankrecord/splash.png"),
                        AlertType.INFO);
    anAlert.setTimeout(1000);
    aDisplay = Display.getDisplay(this);
    aDisplay.setCurrent(anAlert, aList);
  }

  //挂起应用程序
  public void pauseApp() {
  }

  //撤销应用程序
  public void destroyApp(boolean unconditional) {
  }

  /*
   3.响应按钮事件
   */
  public void commandAction(Command c, Displayable s) {
    if (c == exitCommand) {
      destroyApp(false);
      notifyDestroyed();
    }
    else if (c == okCommand) {
      //装入添加窗体
      if (aList.getSelectedIndex() == 0) {
        addForm = new AddRecordForm(aDisplay, aList);
        aDisplay.setCurrent(addForm);
      }

      //装入按姓名排列记录列表
      else if (aList.getSelectedIndex() == 1) {
        recordList = new RecordList(aDisplay, aList, 0);
        aDisplay.setCurrent(recordList);
      }
      //装入按ID排列记录列表
      else if (aList.getSelectedIndex() == 2) {
        recordList = new RecordList(aDisplay, aList, 1);
        aDisplay.setCurrent(recordList);
      }
      //装入按名称查询窗体
      else if (aList.getSelectedIndex() == 3) {
        searchForm = new SearchForm(aDisplay, aList, "按名称查询", 1);
        aDisplay.setCurrent(searchForm);
      }
      //装入按ID号查询窗体
      else if (aList.getSelectedIndex() == 4) {
        searchForm = new SearchForm(aDisplay, aList, "按ID号查询", 2);
        aDisplay.setCurrent(searchForm);
      }
    }
    else {
      aDisplay.setCurrent(aList);
    }

  }

  /*
   4.装入图片
   */
  public Image loadImage(String imageFile) {
    Image anImage;
    try {
      anImage = Image.createImage(imageFile);
    }
    catch (Exception e) {
      anImage = null;
    }
    return anImage;
  }
}

⌨️ 快捷键说明

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