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