import java.awt.*; import java.applet.Applet; /** * ParamInput.java: Defines a panel object that is used for inputing * parameter values (using a text field). * * Written in: Java 1.0.2 * * @author Joseph A. Huwaldt Date: November 23, 1997 * @author Joseph A. Huwaldt Date: December 2, 1997 * @version December 2, 1997 **/ class ParamInput extends Panel { // Define class variables here TextField theTField; // TextField for inputting a value to this parameter. Param theParam; // The parameter that this input panel refers to. /** * Constructor(): * * Written by: Joseph A. Huwaldt Date: November 23, 1997 * Modified by: Joseph A. Huwaldt Date: November 30, 1997 * * @param param The Param object that this input field should use. * @return No return value **/ ParamInput(Param param) { theParam = param; // Create layout setLayout(new BorderLayout()); // Create the label for this parameter. Label theLabel = new Label(theParam.getLabel() + " =", Label.RIGHT); add("West", theLabel); // Create text input field for this parameter. if (param.isDefined()) theTField = new TextField( param.toString(), 10 ); else theTField = new TextField("", 10); add("Center", theTField); // Create holding space for help button. Label tmplabel = new Label(" "); add("South", tmplabel); // Create holding space for units label. Label unitsLabel = new Label(" "); add("East", unitsLabel); } // end ParamInput() Constructor. /** * insets(): We are adding an inset to our Applet panel. This is * called by the container to determine our insets. * * Written by: Joseph A. Huwaldt Date: November 22, 1997 * Modified by: Joseph A. Huwaldt Date: November 29, 1997 * * @param No prameters * @return An Insets object is returned. **/ public Insets insets() { return new Insets(5,0,5,0); } // end insets() /** * getInput(): Reads the value input in the text field and puts it into * the corresponding parameter. The value is also returned * as a float. If the TextEdit field is empty, Float.NaN * is returned and placed in the parameter object. * * Written by: Joseph A. Huwaldt Date: November 23, 1997 * Modified by: Joseph A. Huwaldt Date: November 23, 1997 * * @param No prameters * @return The float value in the TextField is returned. * @exception NumberFormatException If something other than a number is * entered, this exception is thrown. **/ public float getInput() throws NumberFormatException { String s = theTField.getText(); theParam.setValue( s ); return theParam.getValue(); } /** * focusLost(): This is called if the user has changed focus off of this * parameter item. * * Written by: Joseph A. Huwaldt Date: November 23, 1997 * Modified by: Joseph A. Huwaldt Date: November 29, 1997 * * @param FocusEvent A focus event event object is passed from system. * @return No value returned **/ /* public void focusLost(FocusEvent e) { theApplet.update(); } */ } // end ParamInput class