📄 counterclient.java
字号:
/*
* CounterClient.java E.L. 2001-08-25
*
* Here is main() at the client side.
* Contact with the server side is established, and callback object is created.
*/
import java.rmi.*;
import java.rmi.server.*;
import javax.swing.*;
class CounterClient implements Constants {
public static void main(String[] args) throws Exception {
YesNoCounterFront counter = null;
boolean counterFound = false;
do { // try to establish contact with the server
try {
String nameServerMachine = JOptionPane.showInputDialog(null,
"What's the name of the server machine? ");
String url = "rmi://" + nameServerMachine + "/";
counter = (YesNoCounterFront) Naming.lookup(url + counterName);
counterFound = true;
} catch (NotBoundException e) {
JOptionPane.showMessageDialog(null, "The Counter object is not found, " + e);
} catch (UnknownHostException e) {
JOptionPane.showMessageDialog(null, "Unknown machine, " + e);
} catch (java.net.MalformedURLException e) {
JOptionPane.showMessageDialog(null, "Invalid name format, " + e);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error: " + e);
}
} while (!counterFound);
try {
String clientName = JOptionPane.showInputDialog(null, "What's your name:");
System.out.println("Status for " + clientName);
/* This object runs in its own thread which receives messages from the server. */
Client thisClient = new ClientImpl(clientName);
counter.registerMe(thisClient);
/* Sets up the input window */
CounterWindow window = new CounterWindow(counter, thisClient);
window.setLocation(locationCountWindowX, locationCountWindowY);
window.pack();
window.setVisible(true);
} catch (Exception e) {
System.out.println("Error in main(): " + e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -