LabeledTextField.java
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:2k
- /* $Id: LabeledTextField.java,v 1.3 2002/09/09 05:50:39 parasuraman Exp $ */
- /*
- * @(#)LabeledTextField.java
- * Copyright (c) 1996-2002 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
- */
- import java.awt.*;
- import java.awt.event.*;
- import java.util.*;
- /**
- * LabeledTextField object is a Panel that has a Label and a TextField.
- */
- public class LabeledTextField extends Panel {
- public Label label;
- public TextField textfield;
- /**
- * Creates a TextField and a Label.
- * @param labelText Label String
- */
- public LabeledTextField(String labelText) {
- label = new Label(labelText);
- textfield = new TextField(3*labelText.length()); // Some arbitrary length
- thisLayout();
- }
- /**
- * Creates a TextField with the given text and a Label.
- * @param labelText Label String
- * @param tfText Sets this string to the TextField
- */
- public LabeledTextField(String labelText, String tfText) {
- label = new Label(labelText);
- textfield = new TextField(tfText); // Some arbitrary length
- thisLayout();
- }
- /**
- * Creates a TextField with the given length and a Label.
- * @param labelText Label String
- * @param length Length of the TextField
- */
- public LabeledTextField(String labelText, int length) {
- label = new Label(labelText);
- textfield = new TextField(length); // Some arbitrary length
- thisLayout();
- }
- /**
- * Creates a TextField with the given length and text and a Label.
- * @param labelText Label String
- * @param tfText Sets this text to the TextField
- * @param length Length of the TextField
- */
- public LabeledTextField(String labelText, String tfText, int length) {
- label = new Label(labelText);
- textfield = new TextField(tfText,length);
- thisLayout();
- }
- /**
- * Adds the Label and TextField to the FlowLayout
- */
- void thisLayout() {
- setLayout(new FlowLayout(FlowLayout.LEFT));
- add(label);
- add(textfield);
- }
-
- /**
- * Add ActionListener
- */
- public void addActionListener(ActionListener listener) {
- textfield.addActionListener(listener);
- }
- /**
- * Sets font to the Label and text.
- * @param tFont Sets the font to the TextField text
- * @param lFont Sets the font to the Label
- */
- public void setFont(Font tFont, Font lFont) {
- textfield.setFont(tFont);
- label.setFont(lFont);
- }
- }