import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.*;
import javax.swing.*;public class ServerPrinter extends UnicastRemoteObject implements RemotePrinter{
private static int CallTimes=0;
public ServerPrinter() throws RemoteException{super();} public void GoPrint() throws RemoteException{
CallTimes+=1;
System.out.println("Go Print for "+ CallTimes +" times!");
//PrintSample ps = new PrintSample();
//ps.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//ps.pack();
//ps.setVisible(true);
}
public static void main(String[] args) {
try{
System.out.println("Prepare to Start Serving! Please Wait...");
ServerPrinter printer = new ServerPrinter();
System.out.println("Print Server Ready! Start Serving...");
/*NEW Implementation
* Create a registry and bind stub in registry.
*/
LocateRegistry.createRegistry(2002);
Registry registry = LocateRegistry.getRegistry(2002);
registry.rebind("FirstRemote", printer); /*OLD Implementation 这种方法需要外部使用rmiregistry命令
String name= System.getProperty("Printer Name","FirstRemote");
Naming.rebind(name,printer);
*/
System.out.println("Server open and ready for customers!!!");
}
catch(Exception e){
System.err.println(e.toString());
}
}
}
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.*;
import javax.swing.*;public class ServerPrinter extends UnicastRemoteObject implements RemotePrinter{
private static int CallTimes=0;
public ServerPrinter() throws RemoteException{super();} public void GoPrint() throws RemoteException{
CallTimes+=1;
System.out.println("Go Print for "+ CallTimes +" times!");
//PrintSample ps = new PrintSample();
//ps.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//ps.pack();
//ps.setVisible(true);
}
public static void main(String[] args) {
try{
System.out.println("Prepare to Start Serving! Please Wait...");
ServerPrinter printer = new ServerPrinter();
System.out.println("Print Server Ready! Start Serving...");
/*NEW Implementation
* Create a registry and bind stub in registry.
*/
LocateRegistry.createRegistry(2002);
Registry registry = LocateRegistry.getRegistry(2002);
registry.rebind("FirstRemote", printer); /*OLD Implementation 这种方法需要外部使用rmiregistry命令
String name= System.getProperty("Printer Name","FirstRemote");
Naming.rebind(name,printer);
*/
System.out.println("Server open and ready for customers!!!");
}
catch(Exception e){
System.err.println(e.toString());
}
}
}
如何写啊??拜托了!!