/* * NumButtonObj Class * * Developed for "Rethinking CS101", a project of Lynn Andrea Stein's AP Group. * For more information, see the * CS101 homepage or email . * * Copyright (C) 1997 Massachusetts Institute of Technology. * Please do not redistribute without obtaining permission. */ package Calculator; /** * This class is a smart button object that handles the Calculator's * numeric buttons. Every ButtonHandler should have ten ( 0 - 9 ). * * @author: Lynn Andrea Stein, las@ai.mit.edu * @author: Luis F. G. Sarmenta, lfgs@mit.edu * @version: $$ * * @see Calculator, ButtonHandler, ButtonObj */ public class NumButtonObj extends ButtonObj { /** * Which number am I? buttonVal remembers.

* * Initialized by constructor, doesn't change. */ private int buttonVal; /** * How to make one: Make a ButtonObj (i.e., my superclass) and * also remember my number. * * @param num Which numbered button am I? ( 0 - 9 ) * @param gui The CalcTextGUI to keep track of. * @param stateObj The CalculatorState to keep track of. */ public NumButtonObj( int num, CalcTextGUI gui, CalculatorState stateObj ) { super( gui, stateObj ); this.buttonVal = num; // remember my number. } /** * This method is called by the ButtonHandler whenever the * decimal point button is pressed.

* * How to handle (my button) being pressed? Make sure that we're * reading a number (tell the stateObj if it doesn't know) and * then either use this number as the current display or append it * to it if there's already a partial number. */ public void handleButton() { String whatToPrint = Calculator.ButtonLabels[this.buttonVal]; if ( this.stateObj.notReadingNumber() ) // if no number yet, { this.stateObj.startReadingNumber(); this.gui.setText( whatToPrint ); // this is it } else { this.gui.appendText( whatToPrint ); // else just add my num to end. } } } /* * $Log: NumButtonObj.java,v $ * Revision 1.1.1.1 2002/06/05 21:56:25 root * CS101 comes to Olin finally. * * Revision 1.3 1997/10/30 03:28:36 lfgs * Added overview and fixed "* /" commenting typo in code. * * Revision 1.2 1997/10/24 22:20:41 las * Documented all of the code files, but didn't write the user manual (yet). * */