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

📄 mobilebank.java

📁 手机银行测试程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package face;

import java.util.Hashtable;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import com.cuilichen.usual.*;
import com.sunnitech.VirtualBank.nts.*;


public class MobileBank extends MyMIDlet implements CommandListener, Runnable {
    private Form login;
    private Form queryBR;
    private Form queryH;
    private Form queryHR;
    private Form lost;
    private Form transfer;
    private Form keyIn;
    private Form help;
    private Form alert;
    private Form exitF;
    private Form letter;
    private Form cer;
    private List function;
    private List helpList;
    Display display;
    TaskManager tm = new TaskManager("https://security.sunnitech.com/Bank/do");
    private int cardLength = 21; //alertNumber标识警告的对象(提出警告的页面)
    private int task = 0; //alertNumber标识警告的对象(提出警告的页面)
    private String cardNum = ""; //一卡通卡号,转账密码,暂时转账密码和登录密码相同
    private String key = ""; //一卡通卡号,转账密码,暂时转账密码和登录密码相同
    private String harfKey = ""; //一卡通卡号,转账密码,暂时转账密码和登录密码相同
    private String out = ""; //一卡通卡号,转账密码,暂时转账密码和登录密码相同
    private String rsName = "MobileBank"; //一卡通卡号,转账密码,暂时转账密码和登录密码相同
    private TextField cardNumTF;
    private TextField currentKey;
    private TextField targetM;
    private TextField targetCard;
    private TextField balance;
    private TextField newPW;
    private TextField newPW2;
    private Displayable preAlert;
    Command comm[] = { CM.enterCM, CM.backCM, CM.exitCM, CM.nullCM };
    private String orderStr[] = { "查询余额", "查询历史", "挂失账号", "转账", "修改密码", "系统帮助" };

    public MobileBank() {
        RMS.setName(rsName);
        display = Display.getDisplay(this);
    }

    void initLogin() { //登录页面
        login = new Form("登录");
        currentKey = new TextField("请输入密码", "", 8, TextField.NUMERIC);
        cardNumTF = new TextField("请输入账号", cardNum, cardLength, TextField.NUMERIC);
        login.append(currentKey);
        login.append(cardNumTF);
        setCM_Show(0, 2, login);
    }

    void initFunction() { //功能选择页面
        function = new List("chose", List.IMPLICIT);

        for(int i = 0; i < orderStr.length; i++) {
            function.append(orderStr[i], null);
        }

        setCM_Show(0, 1, function);
    }

    void initQueryBR(String balance, int state, String mKind) { //余额查询的结果
        queryBR = new Form("查询结果");
        queryBR.append("余额\n" + balance + "\n币种\n" + mKind + "\n状态\n" + state);
        setCM_Show(1, 2, queryBR);
    }

    void initQueryH() { //查询历史的输入页面
        queryH = new Form("查询历史");
        targetM = new TextField("要查询的年月", "200502", 6, TextField.NUMERIC);
        queryH.append("账号\n" + cardNum + "\n");
        queryH.append(targetM);
        setCM_Show(0, 1, queryH);
    }

    void initQueryHR(String _history) { //查询历史的结果
        queryHR = new Form("查询结果");
        queryHR.append(_history + "\n");

        setCM_Show(1, 2, queryHR);
    }

    void initLost() { //挂失
        lost = new Form("挂失");
        lost.append("您将挂失该账号!\n确认您的操作?");
        setCM_Show(0, 1, lost);
    }

    void initTransfer() { //转帐页面
        transfer = new Form("转账");
        currentKey = new TextField("输入密码", "", 8, TextField.NUMERIC);
        targetCard = new TextField("目标账号", "", cardLength, TextField.NUMERIC);
        balance = new TextField("转账金额", "", 20, TextField.NUMERIC);
        transfer.append(currentKey);
        transfer.append(targetCard);
        transfer.append(balance);
        setCM_Show(0, 1, transfer);
    }

    void initKeyIn() { //修改密码页面
        keyIn = new Form("修改密码");
        currentKey = new TextField("输入原密码", "", 8, TextField.NUMERIC);
        newPW = new TextField("输入新密码", "", 8, TextField.NUMERIC);
        newPW2 = new TextField("确认新密码", "", 8, TextField.NUMERIC);
        keyIn.append(currentKey);
        keyIn.append(newPW);
        keyIn.append(newPW2);
        setCM_Show(0, 1, keyIn);
    }

    void initHelpList() {
        helpList = new List("选择", List.IMPLICIT);
        helpList.append("证书信息", null);
        helpList.append("系统帮助", null);
        setCM_Show(0, 1, helpList);
    }

    void initHelp() { //帮助页面
        help = new Form("帮助");
        help.append("手机银行系统,帮助您轻松理财。\n" + "本系统提供:查询余额、查询历史、挂失、转账、修改密码等功能。\n" + "系统使用简单方便。是您当然的正确选择。");
        setCM_Show(1, 2, help);
    }

    void initAlert(int status, String reason, Displayable _preAlert) { //操作成功或失败,针对各个可能出现错误的页面
        alert = new Form("");

        if(status == 1) {
            alert.setTitle("成功");
            alert.append("恭喜!操作成功!\n");
        } else if(status == 2) {
            alert.setTitle("失败");
            alert.append("注意:操作失败!\n原因:" + reason);
        }

        setCM_Show(1, 2, alert);
        preAlert = _preAlert; //记录输出警告的页面,用于返回。
    }

    private void setCM_Show(int fir, int sec, Displayable disp) {
        disp.addCommand(comm[fir]);
        disp.addCommand(comm[sec]);
        disp.setCommandListener(this);
        display.setCurrent(disp);
    }

    protected void startApp() throws MIDletStateChangeException {
        int num = 0;

        try {
            num = RMS.getNumOfRecords();
        } catch(RecordStoreException e2) {
        }

        if(num == 0) {
            try {
                RMS.addRecord(0, 0, 0, "cardNum", "1001", "", false);
            } catch(RecordStoreException e1) {
            }
        }

        try {
            Appointment apps[] = RMS.getRecords();

            for(int i = 0; i < apps.length; i++) {
                if(apps[i].getStr1().equals("cardNum")) {
                    cardNum = apps[i].getStr2();
                }
            }
        } catch(RecordStoreException e1) {
            e1.printStackTrace();
        }

        try {
            display = Display.getDisplay(this);
            initLogin();
        } catch(Exception e) {
        }
    }

    protected void pauseApp() {
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
    }

    public void commandAction(Command c, Displayable d) {
        try {
            Screen screen = (Screen)d; //TODO

            if(screen == login) {
                if(c == CM.enterCM) {
                    cardNum = cardNumTF.getString(); //取得用户输入的卡号

                    try {
                        RecordStore rs = RecordStore.openRecordStore(rsName, false);
                        RecordEnumeration re = rs.enumerateRecords(null, null, false);

                        for(int i = 0; i < rs.getNumRecords(); i++) {
                            int j = re.nextRecordId();
                            Appointment app = new Appointment(rs.getRecord(j));

                            if(app.getStr1().equals("cardNum")) {
                                RMS.setRecord(j, 0, 0, 0, "cardNum", cardNum, "", false);
                            }
                        }
                    } catch(Exception e) {
                        e.printStackTrace();
                    }

                    key = currentKey.getString();
                    task = Task.TASK_LOGIN;
                    new Thread(this).start();
                }

                if(c == CM.exitCM) {
                    myExit();
                }
            } else if(screen == queryBR) {
                if(c == CM.backCM) { //返回功能选择页面
                    initFunction();
                }

                if(c == CM.exitCM) { //退出
                    myExit();
                }
            } else if(screen == queryH) { //查询历史

                if(c == CM.enterCM) { //进入查询历史结果

                    String ym = targetM.getString();

                    if(ym.length() != 6) {
                        initAlert(2, "日期格式错误", queryH);
                    } else {
                        String month = ym.substring(4, 6);

                        if(Integer.parseInt(month) > 12) {
                            initAlert(2, "日期格式错误", queryH);
                        } else {
                            task = Task.TASK_HISTORY;
                            new Thread(this).start();
                        }
                    }
                }

                if(c == CM.backCM) { //返回功能选择页面
                    initFunction();
                }
            } else if(screen == queryHR) { //查询历史结果

⌨️ 快捷键说明

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