/* * CalcTextGUI.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; import cs101.util.Coerce; /** * This class is a text-only adapter for the Calculator GUI. Each * ButtonHandler should have exactly one instance of CalcTextGUI. * This provides the basic text functionality present in the * Calculator interface (though not the getButton() method) as well as * some additional utility functions. * * @author: Lynn Andrea Stein, las@ai.mit.edu * @version: $$ * * @see Calculator, ButtonHandler */ public class CalcTextGUI { /** * The Calculator that this provides the textual interface to. * Should really be private (or at least protected)!

* Initialized by constructor. Shouldn't change. */ Calculator gui; /** * A CalcTextGUI is an adapter for a Calculator, so we'll need a * Calculator to adapt on behalf of. Otherwise, vanilla * construction. * * @param realGUI the Calculator to adapt. */ public CalcTextGUI( Calculator realGUI ) { this.gui = realGUI; } /** * How to display a String on the Calculator. * * @param s The string to be displayed. */ public void setText( String s ) { this.gui.setText( s ); // just do it. } /** * How to find out what String is displayed on the Calculator. * * @returns The string currently being displayed. */ public String getText() { return this.gui.getText(); // just do it. } /** * How to find out what number is displayed on the Calculator. * * @returns A double representing the currently displayed value. */ public double getValue() { // Get the String, then turn it into a double. return Coerce.StringTodouble( this.gui.getText() ); } /** * How to append something to the String currently displayed on * the Calculator. * * @param s The string to be appended. */ public void appendText( String s ) { // add s to what's already there. this.gui.setText( this.gui.getText() + s ); } /** * How to clear the Calculator's screen. */ public void clearScreen() { // New text is no text. this.gui.setText( "" ); } } /* * $Log: CalcTextGUI.java,v $ * Revision 1.1.1.1 2002/06/05 21:56:25 root * CS101 comes to Olin finally. * * Revision 1.2 1997/10/24 22:20:41 las * Documented all of the code files, but didn't write the user manual (yet). * */