Java Reference
In-Depth Information
public void destroyApp (boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if (c.getLabel().equals ("CLR")) {
operator = '=';
operand1Item.setText ("");
operand2Field.setLabel ("");
operand2Field.setString ("");
operand2Field.setString ("");
}
else {
// 1. apply op
int op2 = MathFP.toFP
(operand2Field.getString()
+ "." + operand2FField.getString());
if (operator != '=') {
int op1 = MathFP.toFP (operand1Item.getText());
switch (operator) {
case '+': op2 = MathFP.add(op1, op2); break;
case '-': op2 = MathFP.sub (op1, op2); break;
case '*': op2 = MathFP.mul (op1, op2); break;
case '/': op2 = MathFP.div (op1, op2); break;
}
}
String result = MathFP.toString (op2);
operator = c.getLabel().charAt (0);
if (operator != '=') {
operand1Item.setText (MathFP.toString (op2));
operand2Field.setLabel (c.getLabel());
operand2Field.setString ("");
operand2FField.setString ("");
}
else {
operand1Item.setText ("");
operand2Field.setLabel ("");
int cut = result.indexOf (".");
if (cut == -1) {
operand2Field.setString (result);
operand2FField.setString ("");
}
else {
operand2Field.setString (result.substring (0,
cut));
operand2FField.setString (result.substring
(cut+1));
}
}
}
}
}
Search WWH ::




Custom Search