bankuser.java
来自「java rmi技术实例」· Java 代码 · 共 52 行
JAVA
52 行
import java.rmi.*;
import java.net.MalformedURLException;
import java.util.Locale;
import java.text.NumberFormat;
public class BankUser {
// Interface reference to BankManager
private BankManager bm;
// No-argument constructor
public BankUser() {
try {
bm = (BankManager)Naming.lookup(
"rmi://localhost:1099/BankSystem");
} catch (MalformedURLException malformedException) {
System.err.println("Bad URL: " + malformedException);
} catch (NotBoundException notBoundException) {
System.err.println("Not Bound: " + notBoundException);
} catch (RemoteException remoteException) {
System.err.println("Remote Exception: " + remoteException);
}
try {
// Lookup account 4461
Account account = bm.getAccount("4461");
// Get client for account
Client client = account.getClient();
// Get name for client
String name = client.getName();
// Get balance for account
long cash = account.getBalance();
// Format and display output
NumberFormat currencyFormat =
NumberFormat.getCurrencyInstance(Locale.US);
String balanceString = currencyFormat.format(cash);
System.out.println(name + "'s account has " + balanceString);
} catch (RemoteException remoteException) {
System.err.println(remoteException);
}
}
public static void main(String[] args) {
new BankUser();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?