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

📄 bankuser.java

📁 java编程好的网上银行的例子
💻 JAVA
字号:
/*
 * 创建日期 2005-9-14
 *
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.*;

import javax.swing.JOptionPane;

public class BankUser extends UnicastRemoteObject implements BankUserInterface {

    private int s, amount, numberCounterAccount;

    private String name, residence, password;

    private int accountNumber = -1;

    private LoginGUI login;

    private BankInterface server;
    
    private SessionGUI sg;

    private Data d;

    BankUser() throws RemoteException {
        try {
            //server = (BankInterface) Naming.lookup("rmi://cy/Bank");
            login = new LoginGUI();
            
        } catch (Exception e) {
        }

    }

    BankUser(boolean b, int an, String p) throws RemoteException {
        // System.out.println(b);
        if (b == true) {
            accountNumber = an;
            s = an;
            password = p;

            try {
                System.out.println("sending login");
                server = (BankInterface) Naming.lookup("rmi://cy/Bank");
                server.registerClient(this);
                d = server.login(accountNumber, password);
                System.out.println("display");
                display1(d);
            } catch (Exception e) {
            }
        }
    }

    BankUser(boolean b, int from, int to, int am) throws RemoteException {
        if (b == true) {
            accountNumber = from;
            s = from;
            numberCounterAccount = to;
            amount = am;
            try {
                System.out.println("sending remit");
                server = (BankInterface) Naming.lookup("rmi://cy/Bank");
                System.out.println("connected");
                server.remit(accountNumber, numberCounterAccount, amount);

            } catch (Exception e) {
            }
        }
    }

    BankUser(boolean b, String n, String re, String p)
            throws java.rmi.RemoteException {
        // System.out.print(b);
        if (b == true) {
            name = n;
            residence = re;
            password = p;
            try {
                System.out.println("sending register");
                server = (BankInterface) Naming.lookup("rmi://cy/Bank");
                server.registerClient(this);
                d = server.registe(name, residence, password);
                s = d.getAccountNumber();
                System.out.println("display");
                display1(d);
            } catch (Exception e) {
            }
        }
    }

    public void display(Data d) throws java.rmi.RemoteException {
        accountNumber = d.getAccountNumber();
        System.out.println(s+"    "+d);
        if (s == accountNumber) {
            System.out.println("............");

                sg.setBalance(d.getBalance());


        }
    }
    
    public void display1(Data d) throws java.rmi.RemoteException {
        accountNumber = d.getAccountNumber();
        System.out.println(s+"    "+d);
        if (s == accountNumber) {
            System.out.println("............");

            if (accountNumber >= 0) {
                sg = new SessionGUI();
                sg.setAccountNumbert(accountNumber);
                sg.setNameResidence(d.getNameResidence());
                sg.setBalance(d.getBalance());
                sg.setAnnouncements((String) d.getMutations().next());
            } else {
                JOptionPane.showMessageDialog(login,
                        "Wrong accountNumber or password", "Error",
                        JOptionPane.WARNING_MESSAGE);
                new BankUser();
            }
        }
    }


    public void exit() {
        try {
            server.logOff(this);
        } catch (Exception e) {
        }
    }

    /**
     * @param args
     */
    public static void main(String[] args) throws java.rmi.RemoteException {
        // TODO 自动生成方法存根
        if (System.getSecurityManager() == null) {
            System.setSecurityManager(new RMISecurityManager());
        }

        try {
            new BankUser();

        } catch (Exception e) {

        }
    }

}

⌨️ 快捷键说明

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