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

📄 datamodel.java

📁 《j2ee经典实例详解》的源代码。原书无附带光盘。介绍的是一个在线银行系统的例子。绝对难得
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2005 Sun Microsystems, Inc.  All rights reserved.  U.S. * Government Rights - Commercial software.  Government users are subject * to the Sun Microsystems, Inc. standard license agreement and * applicable provisions of the FAR and its supplements.  Use is subject * to license terms. * * This distribution may include materials developed by third parties. * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks * or registered trademarks of Sun Microsystems, Inc. in the U.S. and * other countries. * * Copyright (c) 2005 Sun Microsystems, Inc. Tous droits reserves. * * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions * en vigueur de la FAR (Federal Acquisition Regulations) et des * supplements a celles-ci.  Distribue par des licences qui en * restreignent l'utilisation. * * Cette distribution peut comprendre des composants developpes par des * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE * sont des marques de fabrique ou des marques deposees de Sun * Microsystems, Inc. aux Etats-Unis et dans d'autres pays. */package com.sun.ebank.appclient;import java.math.BigDecimal;import java.util.ResourceBundle;import java.util.Date;import java.util.ArrayList;import java.rmi.RemoteException;import javax.naming.InitialContext;import javax.swing.JTextField;import javax.swing.JOptionPane;import com.sun.ebank.ejb.customer.CustomerController;import com.sun.ebank.ejb.customer.CustomerControllerHome;import com.sun.ebank.ejb.exception.CustomerNotFoundException;import com.sun.ebank.ejb.account.AccountController;import com.sun.ebank.ejb.account.AccountControllerHome;import com.sun.ebank.ejb.exception.AccountNotFoundException;import com.sun.ebank.ejb.exception.IllegalAccountTypeException;import com.sun.ebank.ejb.exception.CustomerInAccountException;import com.sun.ebank.ejb.exception.InvalidParameterException;import com.sun.ebank.util.CustomerDetails;import com.sun.ebank.util.AccountDetails;import com.sun.ebank.util.EJBGetter;public class DataModel {    //Private EJB variables    private static CustomerController customer;    private static AccountController account;    //Private instance variables    private BankAdmin frame;    private ResourceBundle messages;    private int currentFunction;    private String returned;    private Date timestamp;    //Protected instance variables    protected String first;    //Protected instance variables    protected String last;    //Protected instance variables    protected String mid;    //Protected instance variables    protected String str;    //Protected instance variables    protected String cty;    //Protected instance variables    protected String st;    //Protected instance variables    protected String zp;    //Protected instance variables    protected String tel;    //Protected instance variables    protected String mail;    //Protected instance variables    protected String descrip;    //Protected instance variables    protected String credit;    //Protected instance variables    protected String type;    //Protected instance variables    protected String bal;    //Protected instance variables    protected String begbal;    //Protected instance variables    protected String custID;    //Protected instance variables    protected String actID;    protected BigDecimal balance;    protected BigDecimal creditline;    protected BigDecimal beginbalance;    protected BigDecimal bigzero = new BigDecimal("0.00");    protected boolean checkbal;    protected boolean checkbegbal;    //Constructor    public DataModel(BankAdmin frame, ResourceBundle messages) {        this.frame = frame;        this.messages = messages;        //Look up and create CustomerController bean        try {            CustomerControllerHome customerControllerHome =                EJBGetter.getCustomerControllerHome();            customer = customerControllerHome.create();        } catch (Exception NamingException) {            NamingException.printStackTrace();        }        //Look up and create AccountController bean        try {            AccountControllerHome accountControllerHome =                EJBGetter.getAccountControllerHome();            account = accountControllerHome.create();        } catch (Exception NamingException) {            NamingException.printStackTrace();        }    }    private String getData(JTextField component) {        String text;        String trimmed;        if (component.getText()                         .length() > 0) {            text = component.getText();            trimmed = text.trim();            return trimmed;        } else {            text = null;            return text;        }    }    protected int checkActData(String returned, int currentFunction) {        this.currentFunction = currentFunction;        this.returned = returned;        if (currentFunction == 6) { //remove account            this.actID = getData(frame.account);            this.custID = getData(frame.customer);            frame.clearMessages(1);            if ((this.custID != null) && (this.actID != null)) {                int success = writeData();                return success;            } else {                frame.messlab5.setText(messages.getString(                        "MissingRequiredException"));                return 1;            }        } else { // create account            //Retrieve data from UI            this.descrip = getData(frame.descrip);            this.bal = getData(frame.bal);            this.credit = getData(frame.credit);            this.begbal = getData(frame.begbal);            this.custID = getData(frame.cust);            //Get type            if (frame.savingsact.isSelected()) {                this.type = "Savings";            } else if (frame.checkingact.isSelected()) {                this.type = "Checking";            } else if (frame.creditact.isSelected()) {                this.type = "Credit";            } else if (frame.mnymktact.isSelected()) {                this.type = "Money Market";            } else {                this.type = null;            }            frame.clearMessages(1);            if (this.begbal != null) {                checkbegbal = begbal.equals("0");            }            //See if user pressed Return after entering            //beginning balance            if (this.bal != null) {                checkbal = bal.equals("0");            }            if (checkbal == true) {                String begbalstring = frame.begbal.getText();                //Assign beginning balance to balance                this.bal = begbalstring;            }            //Convert balance, begin balance, and credit line            //String values to BigDecimal types for            //writing to the database            balance = new BigDecimal(bal);            creditline = new BigDecimal(credit);            beginbalance = new BigDecimal(begbal);            if ((this.custID != null) &&                    (this.begbal != null) &&                    (this.type != null) &&                    (checkbegbal == false)) {                int success = writeData();                return success;            } else {                frame.messlab5.setText(messages.getString(                        "MissingRequiredException"));                return 1;            }        }    }    protected int checkCustData(String returned, int currentFunction) {        this.currentFunction = currentFunction;        this.returned = returned;        int i;        int j;        int k;        this.last = getData(frame.lname);        this.first = getData(frame.fname);        this.mid = getData(frame.mi);        this.str = getData(frame.street);        this.cty = getData(frame.city);        this.st = getData(frame.state);        this.zp = getData(frame.zip);        this.tel = getData(frame.phone);        this.mail = getData(frame.e);        frame.clearMessages(1);        if ((last != null) &&                (first != null) &&                (str != null) &&                (cty != null) &&                (st != null)) {            i = 0;        } else {            frame.messlab5.setText(messages.getString(                    "MissingRequiredException"));            i = 1;        }

⌨️ 快捷键说明

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