// sample.java // Example of a CORBA client running as an applet import java.awt.*; public class sample extends java.applet.Applet { Button connect; Button query; TextArea area; int ROWS = 10, COLS = 20; org.omg.CORBA.ORB orb; Proxy.StreetRouter proxy; public void init() { setLayout( new BorderLayout() ); add("North", area = new TextArea(ROWS, COLS)); area.setText("Applet ready!!!, press connect and send the query\n"); connect = new Button("Connect"); query = new Button("Send Query"); add("Center", connect); add("South", query); } public boolean action (Event e, Object o) { if ( !(e.target instanceof Button) ) return false; if ( ((String)o).equalsIgnoreCase("connect") ) { my_connect(); return true; } if ( ((String)o).equalsIgnoreCase("Send Query") ) { my_send(); return true; } return false; } public void my_connect () { area.setText("CONNECTING TO SERVER...\n"); orb = org.omg.CORBA.ORB.init(this); area.appendText("ORB created...\n"); // For security reasons,it is not possible to connect to other web // server rather than the initial one from you get the applet. In this example // the IOR (the server handler) is obtained from the same web server // that served the applet. If you want to use the InfoBus naming service // you want to make sure both, the InfoBus naming service and your applet, // are under the same web server space. proxy = Proxy.StreetRouterHelper.bind(orb, "http://Eel:15000/StreetRouterSimple.IOR"); //proxy = Proxy.StreetRouterHelper.narrow(naming.GetObject( // "dl/Services/Search","StreetRouterSimple",orb)); area.appendText("PROXY CONTACTED:\n"); area.appendText(proxy.toString()); return; } public void my_send () { area.appendText("Sending this query to the server:\n"); area.appendText("Directions from: Stanford, California \n"); area.appendText(" to: Los Angeles, California \n"); // Sending query to the server .... String directions = proxy.lookupdirections("Stanford", "California", "Los Angeles", "California"); area.appendText(directions); area.appendText("DONE. \n"); return; } }