All Packages Class Hierarchy This Package Previous Next Index
Class Calculator.OpButtonObj
java.lang.Object
|
+----Calculator.ButtonObj
|
+----Calculator.OpButtonObj
- public class OpButtonObj
- extends ButtonObj
This class is a smart button object that handles the Calculator's operations
(+, -, *, /). Every ButtonHandler should have some.
- See Also:
- Calculator
-
NO_OP_BUTTON_OBJ
- The one and only NOOP button.
-
OpButtonObj(int,
ButtonObj, CalcTextGUI, CalculatorState)
- How to make one: Make a ButtonObj (i.e., my superclass) and also
remember which operation I am (Calculator.OP_ADD, etc.), and always
remember that equals button!
-
doOperation(double,
double)
- This method is called when it is actually time to calculate the
result of this operation (i.e., by = button).
-
handleButton()
- This method is called by the ButtonHandler whenever the decimal point
button is pressed.
NO_OP_BUTTON_OBJ
public static final OpButtonObj NO_OP_BUTTON_OBJ
- The one and only NOOP button. It exists mostly to not be one of the
other objects, so the most important thing about it is that it isn't
one of the others. However, it isn't null, either, in case its
handleButton ever gets called. (If its handleButton does get called,
it doesn't do anything. Kind-of like a NOOP, no?)
Initialized here, can't change. Note: static, so it belongs to the
class: OpButtonObj.NO_OP_BUTTON_OBJ. It IS an instance of the class,
though.
OpButtonObj
public OpButtonObj(int op,
ButtonObj equalButton,
CalcTextGUI gui,
CalculatorState stateObj)
- How to make one: Make a ButtonObj (i.e., my superclass) and also
remember which operation I am (Calculator.OP_ADD, etc.), and always
remember that equals button!
- Parameters:
- op - Which buttonID for whichever operation I am.
- equalButton - The equal ButtonObj for this calculator.
- gui - The CalcTextGUI to keep track of.
- stateObj - The CalculatorState to keep track of.
handleButton
public void handleButton()
- This method is called by the ButtonHandler whenever the decimal point
button is pressed.
How to handle (my button) being pressed?
- We're not reading a number any more. Notify state.
- If there's already a pending operation, resolve it by pretending
that the = button was pressed.
- Remember the number that will (eventually) be the left-hand
operand to this operation.
- Overrides:
- handleButton
in class ButtonObj
doOperation
public double doOperation(double leftOperand,
double rightOperand)
- This method is called when it is actually time to calculate the
result of this operation (i.e., by = button). It does the appropriate
numeric calculation on its operands and returns the result, i.e.,
leftOperand + - * / rightOperand as appropriate.
All Packages Class Hierarchy This Package Previous Next Index