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

📄 consumepic.java

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

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

public class ConsumePic extends Canvas implements CommandListener {
  /** Constructor */
  public ConsumePic() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  /**Component initialization*/
  private void jbInit() throws Exception {
    // Set up this Displayable to listen to command events
    setCommandListener(this);
    // add the Exit command
    addCommand(new Command("取消", Command.CANCEL, 1));
  }

  /**Handle command events*/
  public void commandAction(Command command, Displayable displayable) {
    /** @todo Add command handling code */
    if (command.getCommandType() == Command.CANCEL) {
      ConsumeMIDlet.instance.backmain();
    }
  }

  /** Required paint implementation */
  protected void paint(Graphics g) {
    g.setColor(0);
    //获得屏幕大小
    int xm=getWidth();
    int ym=getHeight();
    //绘制背景
    g.fillRect(0,0,xm,ym);
    //将原点移动至左下角
    int x0,y0;
    x0=(int)(xm*0.05);
    y0=(int)(ym*0.95);
    g.setColor(0xffff00);
    //绘制坐标线
    g.drawLine(0,y0,xm,y0);
    g.drawLine(x0,0,x0,ym);
    g.translate(x0, y0);
    RecordStore rs;
    float d[],fmax;
    fmax=0;
    int len;
    try {
      rs = RecordStore.openRecordStore("consume", true);
      len=rs.getNumRecords();
      d=new float[len];
      RecordEnumeration enum = rs.enumerateRecords(null, null, false);
      int i=0;
      while (enum.hasNextElement()) {
        try {
          byte[] data = enum.nextRecord();
          DataInputStream is = new DataInputStream(new ByteArrayInputStream(
              data));
          ConsumeData record = new ConsumeData();
          record.date = new Date();
          record.date.setTime(is.readLong());
          record.Num = is.readFloat();
          if (record.Num>fmax)
            fmax=record.Num;
          d[i]=record.Num;
          i+=1;
          is.close();
        }
        catch (InvalidRecordIDException ex) {
          // Ignore deleted record
        }
      }
      enum.destroy();
      rs.closeRecordStore();
    }
    catch (IOException ie) {return;}
    catch (RecordStoreException e2) {return;}
    int x1,x2,y1,y2;
    x1=0;y1=-(int)(ym*0.9*d[0]/fmax/1.1);
    //绘制曲线
    for (int i=1;i<len;i++){
      x2=(int)(xm*0.9*i/len);
      y2=-(int)(ym*0.9*d[i]/fmax/1.1);
      g.drawLine(x1,y1,x2,y2);
      x1=x2;y1=y2;
    }
    //标注
    g.drawString("日期",xm-x0,0,Graphics.RIGHT|Graphics.BOTTOM);
    g.drawString("金额",x0,-y0,Graphics.LEFT|Graphics.TOP);
  }

}

⌨️ 快捷键说明

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