预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共15页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

RMIMath範例(JDK1.2.2) 問題:在CLIENT端輸入圓半徑讓SERVER傳回計算後圓的周長 1.開啟新Project,命名為math.jpr INTERFACE(新增Mathe.java檔案到Project) packagemath; publicinterfaceMatheextendsjava.rmi.Remote { publicdoublegetRadius(doubler)throwsjava.rmi.RemoteException; } Implement(新增MatheImpl.java檔案到Project) packagemath; importjava.rmi.*; importjava.lang.Math; importjava.rmi.Naming; importjava.rmi.server.UnicastRemoteObject; publicclassMatheImplextendsUnicastRemoteObjectimplementsMathe{ publicMatheImpl()throwsRemoteException { super(); } publicdoublegetRadius(doubler)throwsRemoteException { return2*Math.PI*r; } publicstaticvoidmain(Stringargs[]) { System.setSecurityManager(newRMISecurityManager()); try { MatheImplmath=newMatheImpl(); Naming.rebind("rmi://140.127.43.245/MathServer",math); System.out.println("serverstart...."); } catch(Exceptione) { System.out.println("Servererror:"+e); System.exit(0); } }} File->New->Applet(產生MatheApplet1.java及MatheApplet1.html) packagemath;importjava.awt.*;importjava.awt.event.*;importjava.applet.*;importjava.rmi.*;publicclassMatheApplet1extendsApplet{booleanisStandalone=false;Labellabel1=newLabel();TextFieldradius=newTextField();Labellabel2=newLabel();TextFieldresult=newTextField();Buttonsend=newButton();Mathema;doubleres;//GetaparametervaluepublicStringgetParameter(Stringkey,Stringdef){returnisStandalone?System.getProperty(key,def):(getParameter(key)!=null?getParameter(key):def);}//ConstructtheappletpublicMatheApplet1(){}//Initializetheappletpublicvoidinit(){try{jbInit();}catch(Exceptione){e.printStackTrace();}}//ComponentinitializationprivatevoidjbInit()throwsException{label1.setBounds(newRectangle(37,14,89,36));label1.setFont(newjava.awt.Font("Dialog",0,14));label1.setForeground(Color.red);label1.setText("請輸入圓半徑");this.setLayout(null);radius.setBackground(Color.white);radius.setBounds(newRectangle(157,17,114,31));label2.setBounds(newRectangle(37,111,69,32));label2.setFont(newjava.awt.Font("Dialog",0,14));label2.setForeground(Color.blue);la