In the html\classes subdirectory of your EAServer installation, create a new directory called TutorialApps if it does not exist. In this directory, create the Java file below as JAClient.java.
You can find a copy of JAClient.java in the html/docs/tutorial/java-corba subdirectory of your EAServer installation. Here is the source for JAClient.java:
//
// This is a sample client applet that invokes the
// JavaArithmetic component created in the EAServer
// Java component tutorial.
//
package TutorialApps;
import org.omg.CORBA.*;
import SessionManager.*;
import java.awt.*;
import Tutorial.*; // Package for EAServer stub classes
public class JAClient extends java.applet.Applet {
// User interface controls
Button mult_button;
TextField m1_text;
TextField m2_text;
TextField result_text;
// Component stub instance
Tutorial.JavaArithmetic _comp = null;
public void init()
{
// Draw GUI controls
m1_text = new TextField(" ");
m1_text.setText("2.5");
this.add(m1_text);
Label l1 = new Label("*");
this.add(l1);
m2_text = new TextField(" ");
m2_text.setText("3.1");
this.add(m2_text);
Label l2 = new Label("=");
this.add(l2);
result_text = new TextField(" ");
result_text.setEditable(false);
this.add(result_text);
mult_button = new Button("Multiply");
this.add(mult_button);
//
// Initialize the CORBA client-side ORB and
// obtain a stub for the EAServer component instance.
//
System.out.println("... Creating session.");
//
// Initialize the ORB.
//
java.util.Properties props = new java.util.Properties();
props.put("org.omg.CORBA.ORBClass", "com.sybase.CORBA.ORB");
ORB orb = ORB.init(this, props);
//
// Create an instance of the EAServer SessionManager::Manager
// CORBA IDL object.
//
String ior = this.getParameter("ior");
Manager manager = ManagerHelper.narrow(
orb.string_to_object(ior));
//
// Create an authenticated session with user "Guest" and password
// "GuestPassword".
//
Session session = manager.createSession("Guest", "GuestPassword");
System.out.println("... Creating component instance.");
//
// Create a stub object instance for the
// Tutorial/JavaArithmetic EAServer component.
//
_comp = Tutorial.JavaArithmeticHelper.narrow(
session.create("Tutorial/JavaArithmetic"));
if (_comp == null)
{
System.out.print("ERROR: Null component instance. ");
System.out.print(
"Check Jaguar Manager and verify that the component ");
System.out.print(
"Tutorial/JavaArithmetic exists and that it implements the ");
System.out.println(
"Tutorial::JavaArithmetic IDL interface.");
return;
}
System.out.println("... Created component instance.");
} // init()
// Handle button clicks
public boolean action(Event e, java.lang.Object arg) {
if (e.target == mult_button) {
doMultiply();
return true;
}
else return false;
}
// Call the multiply method and update the displayed result
private void doMultiply() {
// Harvest user input
Double d1 = null;
Double d2 = null;
try {
d1 = new Double(m1_text.getText());
d2 = new Double(m2_text.getText());
} catch (NumberFormatException nfe)
{
this.showStatus("ERROR: Bad number format.");
result_text.setText("");
return;
}
// Call the server component method
double m1 = d1.doubleValue();
double m2 = d2.doubleValue();
try {
double result = _comp.multiply(m1, m2);
result_text.setText((new Double(result)).toString());
}
catch (org.omg.CORBA.SystemException se)
{
System.out.println(
"Exception executing multiply method: "
+ se.toString() );
se.printStackTrace();
}
} // doMultiply
}
Compile the applet source using a JDK 1.2 or later compiler, for example:
%JAGUAR%\bin\jc JAClient.java
| Copyright © 2005. Sybase Inc. All rights reserved. |
|
|