on 07-23-2004 4:29 AM
Hi All,
i am creating Calaculator examle according to given steps,
everything was fine
When i copy javabean code from example into java editor,
it giving error means could not able to save , it giving red sign left side.
regards,
krishna
try this ---
package com.sap.examples.calculator.beans;
import javax.naming.InitialContext;
import com.sap.examples.calculator.Calculator;
import com.sap.examples.calculator.CalculatorHome;
import javax.rmi.PortableRemoteObject;
/**
@author asisodia
*
To change the template for this generated type comment go to
Window>Preferences>Java>Code Generation>Code and Comments
*/
public class CalcProxy {
private Calculator calc;
public void init() throws Exception {
//Lookup the enterprise bean
try {
InitialContext ctx = new InitialContext();
Object ob = ctx.lookup("ejb/CalculatorBean");
CalculatorHome home =
(CalculatorHome) PortableRemoteObject.narrow(
ob,
CalculatorHome.class);
//Initialize the enterprise bean
calc = home.create();
} catch (Exception e) {
throw new Exception(
"Error instantiating Calculator EJB .." + e.toString());
}
}
public CalcProxy() throws Exception {
init();
}
public float getResult(
String firstNumber,
String secondNumber,
String expression)
throws Exception {
float result = 0;
try {
if (firstNumber != null && secondNumber != null) {
//Parse the input parameters
float first = Float.parseFloat(firstNumber);
float second = Float.parseFloat(secondNumber);
int expr = Integer.parseInt(expression);
//Invoke the relevant method of the enterprise bean
switch (expr) {
case 1 :
result = calc.multiply(first, second);
break;
case 2 :
result = calc.divide(first, second);
break;
case 3 :
result = calc.add(first, second);
break;
case 4 :
result = calc.subtract(first, second);
break;
}
}
} catch (Exception re) {
throw new Exception("Fill in all required fields with appropriate values!");
}
//Return the result of the calculation
return result;
}
amit
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.