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

📄 addrecordform.java

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

import javax.microedition.lcdui.*;

class AddRecordForm
    extends Form
    implements CommandListener {
  //声明一个Display对象
  private Display display;

  //声明一个Displayable对象承载父窗体
  private Displayable parent;

  //声明一个代表记录中ID号的文本域TextField
  private TextField idTextField;

  //声明一个代表记录中姓名的文本域TextField
  private TextField nameTextField;

  //声明一个代表记录中积分的文本域TextField
  private TextField scoreTextField;

  //声明一个代表记录中排名的文本域TextField
  private TextField rankTextField;

  //声明一个代表记录中日期的文本域TextField
  private TextField dateTextField;

  //private StringItem idString;
  //声明一个返回上一级窗体按钮Command对象
  private Command backCommand;

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

  //声明一个自定义的记录存储类对象
  RecordDB rdb;

  //声明一个代表记录个数的变量
  String numRecord;

  /*
    1.构造器
   */
  public AddRecordForm(Display d, Displayable p) {
    super("添加记录");
    display = d;
    parent = p;

    RecordDB rdb = new RecordDB();
    numRecord = String.valueOf(rdb.getnumStore() + 1);

    idTextField = new TextField("输入ID号", numRecord, 2, TextField.NUMERIC);
    nameTextField = new TextField("输入姓名", "", 30, TextField.ANY);
    scoreTextField = new TextField("输入积分", "", 16, TextField.NUMERIC);
    rankTextField = new TextField("输入名次", "", 16, TextField.NUMERIC);
    dateTextField = new TextField("输入日期", "", 30, TextField.ANY);

    append(idTextField);
    append(nameTextField);
    append(scoreTextField);
    append(rankTextField);
    append(dateTextField);

    backCommand = new Command("返回", Command.BACK, 1);
    okCommand = new Command("确认", Command.OK, 1);
    addCommand(backCommand);
    addCommand(okCommand);
    setCommandListener(this);
  }

  /*
   2.响应按钮事件
   */
  public void commandAction(Command c, Displayable s) {
    if (c == backCommand) {
      display.setCurrent(parent);
    }
    else {
      RecordDB rdb = new RecordDB();
      int _id = Integer.parseInt(idTextField.getString());
      String _name = nameTextField.getString();
      String _score = scoreTextField.getString();
      String _rank = rankTextField.getString();
      String _date = dateTextField.getString();

      int recordID = rdb.getRecordIDByID(_id);
      //如果记录存储中没有id记录,则加入
      if (recordID == -1) {
        rdb.addRecord(_id, _name, _score, _rank, _date);
      }
      else {
        rdb.modifyRecord(_id, _name, _score, _rank, _date);
      }
      rdb.closeRS();
      display.setCurrent(parent);
    }
  }
}

⌨️ 快捷键说明

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