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

📄 viewaccountform.java

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

package net.bccn.account.ui;

import java.util.Date;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.TextField;
import net.bccn.account.model.Account;
import net.bccn.account.util.Record;
import net.bccn.account.util.Util;

/**
 *
 * @author hadeslee
 */
public class ViewAccountForm extends Form implements CommandListener,ItemStateListener {
    private static ViewAccountForm vf;
    private ChoiceGroup type,detail,aboutDate;//类型和细节
    private TextField money,remark;//金额,备注
    private DateField date,from;//日期真正和起始
    private Command ok,back,reset,viewAll;//OK,返回,重置,查看所有的按钮
    private String[] output=new String[]{"不限","日常用品","化妆品","交通","服装",
    "娱乐","书籍报纸","其它"};
    private String[] input=new String[]{"不限","工资","奖金","外快","其它"};
    private Image[] outputImage,inputImage;
    /**
     * Creates a new instance of ViewAccountForm
     */
    private ViewAccountForm() {
        super("请选择查询账目的方式");
        initImage();
        initWindow();
    }
    public Image[] getOutput(){
        return outputImage;
    }
    public Image[] getInput(){
        return inputImage;
    }
    private void initImage(){
        outputImage=new Image[8];
        inputImage=new Image[5];
        try{
            outputImage[0]=Image.createImage(this.getClass().getResourceAsStream("image/all.png"));
            outputImage[1]=Image.createImage(this.getClass().getResourceAsStream("image/richang.png"));
            outputImage[2]=Image.createImage(this.getClass().getResourceAsStream("image/huazhuang.png"));
            outputImage[3]=Image.createImage(this.getClass().getResourceAsStream("image/jiaotong.png"));
            outputImage[4]=Image.createImage(this.getClass().getResourceAsStream("image/fuzhuang.png"));
            outputImage[5]=Image.createImage(this.getClass().getResourceAsStream("image/yule.png"));
            outputImage[6]=Image.createImage(this.getClass().getResourceAsStream("image/shuji.png"));
            outputImage[7]=Image.createImage(this.getClass().getResourceAsStream("image/qita.png"));
            inputImage[0]=outputImage[0];
            inputImage[1]=Image.createImage(this.getClass().getResourceAsStream("image/gongzi.png"));
            inputImage[2]=Image.createImage(this.getClass().getResourceAsStream("image/jiangjin.png"));
            inputImage[3]=Image.createImage(this.getClass().getResourceAsStream("image/waikuai.png"));
            inputImage[4]=outputImage[7];
        } catch(Exception exe){
            exe.printStackTrace();
        }
    }
    public static ViewAccountForm getInstance(){
        if(vf==null){
            vf=new ViewAccountForm();
        }
        return vf;
    }
    private Account getSampleAccount(){
        Account ac=new Account();
        int index=type.getSelectedIndex();
        if(index!=0){
            ac.setType(type.getString(index));
        }
        index=detail.getSelectedIndex();
        if(index!=0){
            ac.setDetail(detail.getString(index));
        }
        
        if(money.getString()!=null&&!money.getString().equals("")){
            ac.setMoney(Float.parseFloat(money.getString()));
        }
        if(remark.getString()!=null&&!remark.getString().equals("")){
            ac.setRemark(remark.getString());
        }
        index=aboutDate.getSelectedIndex();
        if(index!=0){
            if(index==1){
                ac.setDate(date.getDate());
                ac.setMask(Account.DAY|Account.MONTH|Account.YEAR);
            }else if(index==2){
                ac.setDate(date.getDate());
                ac.setFrom(from.getDate());
                ac.setPhase();
            }
        }
        return ac;
    }
    
    private void initWindow(){
        type=new ChoiceGroup("账目类型",Choice.POPUP,
                new String[]{"不限","支出","收入"},null);
        type.setSelectedIndex(0,true);
        detail=new ChoiceGroup("详细",Choice.POPUP,
                new String[]{"不限","日常用品","化妆品","交通","服装",
                "娱乐","书籍报纸","其它"},outputImage);
        money=new TextField("金额",null,8,TextField.DECIMAL);
        remark=new TextField("备注",null,20,TextField.ANY);
        aboutDate=new ChoiceGroup("日期类型",Choice.POPUP,
                new String[]{"不限","按日期","按区间"},null);
        
        date=new DateField("日期",DateField.DATE);
        date.setDate(new Date());
        from=new DateField("起始日期",DateField.DATE);
        from.setDate(new Date());
        this.append(type);
        this.append(detail);
        this.append(money);
        this.append(remark);
        this.append(aboutDate);
        ok=new Command("确定",Command.OK,1);
        back=new Command("返回",Command.BACK,0);
        reset=new Command("重置",Command.CANCEL,2);
        viewAll=new Command("查看所有",Command.OK,3);
        this.addCommand(ok);
        this.addCommand(back);
        this.addCommand(reset);
        this.addCommand(viewAll);
        this.setCommandListener(this);
        this.setItemStateListener(this);
    }
    public void commandAction(Command command, Displayable displayable) {
        if(command==ok){
            Account temp=getSampleAccount();
            Record[] recs=Util.getAllRecords(temp);
            Account[] as=new Account[recs.length];
            for(int i=0;i<recs.length;i++){
                as[i]=(Account)recs[i];
            }
            ViewAccount.showAccount(as);
            Util.changeTo(Util.VIEW_ACCOUNT);
        }else if(command==back){
            Util.changeTo(Util.MAIN_FORM);
        }else if(command==reset){
            reset();
        }else if(command==viewAll){
            Record[] recs=Util.getAllRecords(new Account());
            Account[] as=new Account[recs.length];
            for(int i=0;i<recs.length;i++){
                as[i]=(Account)recs[i];
            }
            ViewAccount.showAccount(as);
            Util.changeTo(Util.VIEW_ACCOUNT);
        }
    }
    public void itemStateChanged(Item item){
        if(item==type){
            int index=type.getSelectedIndex();
            if(index==1){
                detail.deleteAll();
                for(int i=0;i<output.length;i++){
                    detail.insert(i,output[i],outputImage[i]);
                }
            }else if(index==2){
                detail.deleteAll();
                for(int i=0;i<input.length;i++){
                    detail.insert(i,input[i],inputImage[i]);
                }
            }
        }else if(item==aboutDate){
            int index=aboutDate.getSelectedIndex();
            if(index==0){
                reset();
            }else if(index==1){
                reset();
                date.setLabel("日期");
                this.append(date);
                Util.moveTo(date);
                date.setDate(new Date());
            }else if(index==2){
                reset();
                date.setLabel("结束日期");
                this.append(from);
                this.append(date);
                Util.moveTo(from);
                from.setDate(new Date());
                date.setDate(new Date());
            }
            
        }
        if(aboutDate.getSelectedIndex()==2&&(item==date||item==from)){
            Date fromD=from.getDate();
            Date toD=date.getDate();
            if(fromD.getTime()/86400000>toD.getTime()/86400000){
                Util.showINFO(AlertType.ERROR,"起始日期不能大于结束日期!!");
                if(item==date){
                    date.setDate(new Date());
                }else{
                    from.setDate(new Date());
                }
            }
        }
        
    }
    private void reset(){
        this.deleteAll();
        this.append(type);
        this.append(detail);
        this.append(money);
        this.append(remark);
        this.append(aboutDate);
    }
}

⌨️ 快捷键说明

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