// This appears in Core Web Programming from // Prentice Hall Publishers, and may be freely used // or adapted. 1997 Marty Hall, hall@apl.jhu.edu. import java.awt.*; /** A TextField with an associated Label. * @see LabeledTextArea * @see LabeledChoice * @see LabeledList * @see LabeledSlider */ public class LabeledTextField extends Panel { private Label label; private TextField textField; public LabeledTextField(String labelString, Font labelFont, int textFieldSize, Font textFont) { setLayout(new FlowLayout(FlowLayout.LEFT)); label = new Label(labelString, Label.RIGHT); if (labelFont != null) label.setFont(labelFont); add(label); textField = new TextField(textFieldSize); if (textFont != null) textField.setFont(textFont); add(textField); } public LabeledTextField(String labelString, String textFieldString) { this(labelString, null, textFieldString, textFieldString.length(), null); } public LabeledTextField(String labelString, int textFieldSize) { this(labelString, null, textFieldSize, null); } public LabeledTextField(String labelString, Font labelFont, String textFieldString, int textFieldSize, Font textFont) { this(labelString, labelFont, textFieldSize, textFont); textField.setText(textFieldString); } /** The Label at the left side of the LabeledTextField. * To manipulate the Label, do: *
   *    LabeledTextField ltf = new LabeledTextField(...);
   *    ltf.getLabel.someLabelMethod(...);
   *  
* * @see #getTextField */ public Label getLabel() { return(label); } /** The TextField at the right side of the * LabeledTextField. * * @see #getLabel */ public TextField getTextField() { return(textField); } }