package xthinlet.demo;
import java.io.IOException;
import java.io.InputStream;
import xthinlet.XThinlet;
/**
* @author Koen Roevens
*/
public class Calculator {
private XThinlet x;
public Calculator(XThinlet x) throws IOException {
this.x = x;
parse();
}
private void parse() throws IOException {
InputStream stream = getClass().getResourceAsStream("calculator.xml");
x .add(x.parse(stream,this));
}
public void calculate(String number1, String number2, Object result) {
try {
int i1 = Integer.parseInt(number1);
int i2 = Integer.parseInt(number2);
x.setString(result, "text", String.valueOf(i1 + i2));
} catch (NumberFormatException nfe) {
x.setString(result, "text", "error");
}
}
}
|