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

📄 viewaccount.java

📁 J2ME编的手机助手 文件下载解压缩以后,是一个NetBeans的工程文件,如果有NB的朋友,可以直接打开编辑 源文件在src目录下面,可执行文件在dist目录下 功能如下 1
💻 JAVA
字号:
/*
 * ViewAccount.java
 *
 * Created on 2007年3月11日, 下午9:59
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package net.bccn.account.ui;

import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import net.bccn.account.model.Account;
import net.bccn.account.util.Util;

/**
 *
 * @author hadeslee
 */
public class ViewAccount extends List implements CommandListener{
    private static ViewAccount va;
    private Command back,stat;//大命令,返回,统计
    private Command modify,delete,view;//小命令,修改,删除,查看,
    private Account[] as;//当前账目数组
    /** Creates a new instance of ViewAccount */
    private ViewAccount() {
        super("账目清单",Choice.EXCLUSIVE);
        initWindow();
    }
    private void initWindow(){
        back=new Command("返回",Command.BACK,0);
        stat=new Command("统计",Command.SCREEN,2);
        modify=new Command("修改",Command.SCREEN,3);
        view=new Command("查看",Command.SCREEN,1);
        delete=new Command("删除",Command.SCREEN,4);
        this.addCommand(back);
        this.addCommand(stat);
        this.addCommand(modify);
        this.addCommand(view);
        this.addCommand(delete);
        this.setCommandListener(this);
    }
    public static void showAccount(Account[] as){
        if(va==null){
            va=new ViewAccount();
        }
        va.deleteAll();
        va.as=as;
        for(int i=0;i<as.length;i++){
            va.append(as[i].toString(),null);
        }
        va.setFitPolicy(List.TEXT_WRAP_OFF);
    }
    public static ViewAccount getInstance(){
        if(va==null){
            va=new ViewAccount();
        }
        return va;
    }
    public static void updateList(Account aw){
        for(int i=0;i<va.as.length;i++){
            if(aw.getID()==va.as[i].getID()){
                va.as[i]=aw;
                va.set(i,aw.toString(),null);
            }
        }
    }
    public void commandAction(Command command, Displayable displayable) {
        if(command==back){
            Util.changeTo(Util.VIEW_ACCOUNT_FORM);
        }else if(command==stat){
            float allIn=0,allOut=0;//总收入,总支出
            int in=0,out=0;//收入的笔数,支出的笔数
            for(int i=0;i<as.length;i++){
                if(as[i].getType().equals("支出")){
                    allOut+=as[i].getMoney();
                    out++;
                }else{
                    allIn+=as[i].getMoney();
                    in++;
                }
            }
            String info="您此次统计共"+as.length+"笔:结果如下:\n" +
                    "总共收入:"+in+"笔,合计:"+allIn+"元\n" +
                    "总共支出:"+out+"笔,合计:"+allOut+"元\n" +
                    "总结余:"+(allIn-allOut)+"元\n\n";
            String temp="";
            float sum=allIn-allOut;
            if(sum<0){
                temp="您现在入不敷出了,节省点用吧!";
            }else if(sum<100){
                temp="不错,有余就还行了!";
            }else if(sum<1000){
                temp="很好,再接再励吧!!";
            }else if(sum<5000){
                temp="好好存钱,回家过年!!";
            }else if(sum<10000){
                temp="您还真不错,加油!~!";
            }else{
                temp="您的未来将无限光明,哈哈哈哈!!";
            }
            info+=temp;
            Util.showINFO(AlertType.INFO,info);
            
        }else if(command==modify){
            Account current=as[this.getSelectedIndex()];
            Util.moveTo(AddAccount.getInstance(current,true));
        }else if(command==view){
            Account current=as[this.getSelectedIndex()];
            Util.moveTo(AddAccount.getInstance(current,false));
        }else if(command==delete){
            int index=this.getSelectedIndex();
            Account current=as[index];
            boolean b=Util.deleteRecord(current);
            if(b){
                Util.showINFO(AlertType.INFO,"删除记录成功!!");
                Account[] newAs=new Account[as.length-1];
                boolean add=false;
                //如果找到了删除的那个下标,那么后面的元素就要加一了
                for(int i=0;i<newAs.length;i++){
                    
                    if(i==index){
                        add=true;
                    }
                    if(add){
                        newAs[i]=as[i+1];
                    }else{
                        newAs[i]=as[i];
                    }
                }
                as=newAs;
                this.delete(index);
            }else{
                Util.showINFO(AlertType.ERROR,"删除记录失败!!");
            }
        }
    }
    
}

⌨️ 快捷键说明

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