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

Variable Index

 o NO_OP_BUTTON_OBJ
The one and only NOOP button.

Constructor Index

 o 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!

Method Index

 o doOperation(double, double)
This method is called when it is actually time to calculate the result of this operation (i.e., by = button).
 o handleButton()
This method is called by the ButtonHandler whenever the decimal point button is pressed.

Variables

 o 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.

Constructors

 o 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.

Methods

 o 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?

Overrides:
handleButton in class ButtonObj
 o 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