import java.awt.*; import java.awt.event.*; import StringModifier; /** * Objects that listen to buttons and, in response, modify a * TextField in an AWT application. You need one FieldModifier * per type of modification per field. * * @author Samuel A. Rebelsky * @version 1.0 of February 1999 */ public class FieldModifier implements ActionListener { // +----------------------------------------------------------- // | Fields | // +--------+ // No, this doesn't modify these kinds of fields; it modifies // the text in a TextField in an AWT. /** The field to modify. */ protected TextField field; /** The string modifier used to modify its contents. */ protected StringModifier stringmod; // +--------------+--------------------------------------------- // | Constructors | // +--------------+ /** * Build a new FieldModifier that can modify a particular field * using a particular modifier. */ public FieldModifier(TextField field, StringModifier stringmod) { this.field = field; this.stringmod = stringmod; } // FieldModifier(TextField,StringModifier) // +---------+------------------------------------------------- // | Methods | // +---------+ /** * When asked to perform an action, modify the field. Used a * ``long form'' for the code, which could be expressed more * succinctly. */ public void actionPerformed(ActionEvent evt) { // Get the contents of the field. String str = field.getText(); // Update the string str = stringmod.modify(str); // And replace the contents of the field. field.setText(str); } // actionPerformed(ActionEvent) } // class FieldModifier