/* * DotButtonObj 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 * decimal point. Every ButtonHandler should have one. * * @author: Lynn Andrea Stein, las@ai.mit.edu * @author: Luis F. G. Sarmenta, lfgs@mit.edu * @version: $$ * * @see Calculator, ButtonHandler, ButtonObj */ public class DotButtonObj extends ButtonObj { /** * It turns out that you need the zero button in case the first * button after an operator is dot. In this case, it is * convenient to pretend that the zero has been pressed first. So * hold on to that zero ButtonObj!

* * Initialized by constructor, doesn't change. */ private ButtonObj zeroButton; /** * How to make one: Make a ButtonObj (i.e., my superclass) and * also remember that zero button. * * @param zeroButton The zero ButtonObj for this calculator. * @param gui The CalcTextGUI to keep track of. * @param stateObj The CalculatorState to keep track of. */ public DotButtonObj( ButtonObj zeroButton, CalcTextGUI gui, CalculatorState stateObj ) { super( gui, stateObj ); this.zeroButton = zeroButton; } /** * This method is called by the ButtonHandler whenever the * decimal point button is pressed.

* * How to handle (my button) being pressed? If we're already * reading a number, add the decimal point to the text and have * the state remember. If we're not reading a number (e.g., we * just saw an operation), pretend that the 0 was pressed first. */ public void handleButton() { if ( this.stateObj.notReadingNumber() ) // check whether we need { // to pretend that the 0 this.zeroButton.handleButton(); // button was pressed. } // now do dot press -- but only if we haven't already seen a // decimal point in this number. if ( this.stateObj.noDotYet() ) { this.stateObj.justSawDot(); this.gui.appendText( "." ); } } } /* * $Log: DotButtonObj.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:35 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). * */