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

📄 inputdata.java

📁 手机软件开发,输入界面程序,主要功能完成使用手机记录每天消费的流水帐,该程序是整个程序的一部分
💻 JAVA
字号:
package consume;

import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.rms.*;

public class InputData extends Form implements CommandListener {
  /** Constructor */
  DateField df;
  TextField tf;
  public InputData() {
    super("Input Consume Data");
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  /**Component initialization*/
  private void jbInit() throws Exception {
    df=new DateField("消费日期",DateField.DATE_TIME);
    append(df);
    tf=new TextField("消费金额",null,10,TextField.DECIMAL);
    append(tf);
    // Set up this Displayable to listen to command events
    setCommandListener(this);
    // add the Exit command
    addCommand(new Command("返回", Command.BACK , 1));
    addCommand(new Command("保存", Command.OK, 1));
  }

  /**Handle command events*/
  public void commandAction(Command command, Displayable displayable) {
    /** @todo Add command handling code */
    if (command.getCommandType() == Command.OK) {
      ConsumeData a = new ConsumeData();
      a.setData(df.getDate(), Float.parseFloat(tf.getString()));
      //todo存储数据至数据存储
      // Create the output streams
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      DataOutputStream os = new DataOutputStream(baos);
      // Write the values to be saved to the output streams
      RecordStore rs;
      try {
        os.writeLong(a.date.getTime());
        os.writeFloat(a.Num);
        os.close();
        // Get the byte array with the saved values
        byte[] data = baos.toByteArray();
        rs = RecordStore.openRecordStore("consume", true);
        rs.addRecord(data, 0, data.length);
        rs.closeRecordStore();
      }
      catch (IOException ie) {
      }
      catch (RecordStoreException e2) {
      }
      Alert ta = new Alert("信息", "记录已加入", null, AlertType.INFO);
      df.setDate(null);
      tf.setString("");
      ConsumeMIDlet.instance.dis.setCurrent(ta, this);
    }
    if (command.getCommandType() == Command.BACK) {
      ConsumeMIDlet.instance.backmain();
    }
  }
}

⌨️ 快捷键说明

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