// This file contains excerpts from the textbook Concrete // Abstractions: An Introduction to Computer Science Using Scheme, by // Max Hailperin, Barbara Kaiser, and Karl Knight, Copyright (c) 1998 // by the authors. Full text is available for free at // http://www.gustavus.edu/+max/concrete-abstractions.html import java.awt.*; import java.awt.event.*; public class FormattedField extends TextField implements ActionListener { private double value; private java.text.Format fmt; public FormattedField(int width, java.text.Format f){ super(width); fmt = f; addActionListener(this); } public void actionPerformed(ActionEvent evt){ try{ valueEntered(fmt.parseObject(getText())); } catch(java.text.ParseException e){ // illegal entry, leave alone } } public void valueEntered(Object value){ // typically a subclass will override this } public void setValue(Object value){ setText(fmt.format(value)); } }