import java.applet.Applet;
import java.awt.Graphics;
import
java.rmi.Naming;
import
java.rmi.RemoteException;
String message = "blank"; // the string constructed in the try statement
Hello obj = null;
public void init() {
try
{
//
"//<hostname>/<objectname>"
obj = (Hello)Naming.lookup("//lysander.cs.ucsb.edu/HelloServer");
message = obj.sayHello();
} catch (Exception e) {
System.out.println("HelloApplet exception: " + e.getMessage());
e.printStackTrace();
}
}
public void paint(Graphics g) {
g.drawString(message, 25, 50);
}
}
<HTML>
<title>Hello World</title>
<center> <h1>Hello
World</h1> </center>
The
message from the
HelloServer is:
<p>
<applet code="examples.helloApplet.HelloApplet.class"
width=500 height=120>
</applet>
</HTML>
While in the source directory
where these files reside, execute:
javac -d $HOME/packages Hello.java HelloImpl.java HelloApplet.java
rmic examples.helloApplet.HelloImpl
Start the RMI registry
For example, on Solaris:rmiregistry &
For example, on Windows 95 or Windows NT:
start rmiregistry
- For more on the rmiregistry, please refer to the Solaris rmiregistry manual page or the Win32 rmiregistry manual page.
Start the server
- For Solaris:
java examples.helloApplet.HelloImpl &
- For Windows:
java examples.helloApplet.HelloImplRun the client
Once the registry and server are running, the client can be run as follows, from within the directory that contains the html file:After running the client, you will see "Hello world!".
appletviewer HelloApplet.html