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

📄 setaccountinfo.java

📁 联网斗地主 java版本 用jbuilder2005编写
💻 JAVA
字号:
package poker;

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

public class setAccountInfo extends Form implements CommandListener {
  /** Constructor */
  TextField Account;
  TextField Password;
  Command exitCmd, okCmd, downCmd, cancelCmd, helpCmd, closeCmd, setAccountCmd,
      startGameCmd;
  RecordStore rs = null;
  static setAccountInfo _instance;

  static synchronized public setAccountInfo getInstance() {
    if (_instance == null) {
      _instance = new setAccountInfo();
    }
    return _instance;
  }

  public setAccountInfo() {
    super("set account");
    try {
      jbInit();
      int ss = this.hashCode();
      System.out.println(ss);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  /**Component initialization*/
  private void jbInit() throws Exception {
    Account = new TextField("Account:", "", 8, TextField.EMAILADDR);
    Password = new TextField("PassWord:", "", 8, TextField.PASSWORD);
    okCmd = new Command("OK", Command.OK, 1);
    cancelCmd = new Command("cancel", Command.CANCEL, 1);
    helpCmd = new Command("help", Command.HELP, 1);
    startGameCmd = new Command("", Command.SCREEN, 1);
    setAccountCmd = new Command("set Account", Command.SCREEN, 2);
    this.setCommandListener(this);
    this.addCommand(okCmd);
    this.append(Account);
    this.append(Password);

    // Set up this Displayable to listen to command events
    setCommandListener(this);
    // add the Exit command
    addCommand(cancelCmd);
    addCommand(new Command("Exit", Command.EXIT, 1));
    readFromRms();
  }

  /**Handle command events*/
  public void commandAction(Command c, Displayable d) {
    /** @todo Add command handling  */
    if (c == okCmd) {
      if (Account.getString().trim() == "") {
        Account.setString("you must input a account!");
        return;
      }
      if (Password.getString().trim() == "") {
        Password.setString("you must input a password!");
        return;
      }
      writeRMSfromList();
      Login login = Login.getInstance();
      Func.MsgBox.setString("Account edit OK.");
      Func.MsgBox.setTimeout(2000);
      Func.MsgBox.setTitle("OK");
      Func.MsgBox.setType(AlertType.INFO);
      GameInfo.display.setCurrent(Func.MsgBox,login);
      login.drawFace();
    }
    if (c.getLabel() == "Exit") {
      System.out.println("press exit");
    }
    if (c == cancelCmd) {
      //back to login
      System.out.println("press cancel");
      Login login = Login.getInstance();
      GameInfo.display.setCurrent(login);
      login.drawFace();
    }
  }

  private void writeRMSfromList() {
    try {
      try {
        rs.closeRecordStore();
      }
      catch (Exception e1) {}
      ;
      RecordStore.deleteRecordStore("db_AccountInfo");
    }
    catch (Exception e) {
      Error.errCode = 1;
      Error.errStr = "Error when delete RMS.";
      return;
    }

    try {
      rs = RecordStore.openRecordStore("db_AccountInfo", true);
      DbAccount.set(Account.getString(), Password.getString());
      rs.addRecord(DbAccount.recordByte, 0, DbAccount.recordByte.length);
      rs.closeRecordStore();
      System.out.println("save account ok");
    }
    catch (Exception e) {
      Error.errCode = 1;
      Error.errStr = "Error when read RMS after delete";
      return;
    }
  }

  private void readFromRms() {
    try {
      rs = RecordStore.openRecordStore("db_AccountInfo", true);
      int len = rs.getNumRecords();
      DbAccount.get(rs.getRecord(1));
      String account = DbAccount.account;
      String password = DbAccount.password;
      System.out.println(account + password);
      rs.closeRecordStore();
      Account.setString(account);
      Password.setString(password);
    }catch (Exception e){}
  }
}

⌨️ 快捷键说明

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