?? viewaccountform.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 + -