//package examples.hello; import java.awt.*; import java.rmi.*; import java.net.*; public class HelloApplet extends java.applet.Applet { String message = ""; // The init method begins the execution of the applet on the client // machine that is viewing the Web page containing the reference // to the applet. public void init() { try { // Looks up the server using the name server on the host that // the applet came from. Hello obj = (Hello)Naming.lookup( "//" + getCodeBase().getHost() + "/HelloServer"); // Calls the sayHello method on the remote object. message = obj.sayHello(); } catch (RemoteException e) { System.out.println("HelloApplet RemoteException caught"); } catch (NotBoundException e) { System.out.println("HelloApplet NotBoundException caught"); } catch (MalformedURLException e) { System.out.println("HelloApplet MalformedURLException caught"); } } public void paint(Graphics g) { // The applet will write the string returned by the remote method // call on the display. g.drawString(message, 25, 50); } };