textfields

textfields - CSc 2700: Lecture # 17 Textfields October 28,...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSc 2700: Lecture # 17 Textfields October 28, 2008 1 Introduction A text field holds one line of text (a string) and can be used for input or output. Here are the basics: Class: JTextField Generates: ActionEvent when a user presses "Enter". Listener: Must implement ActionListener Listener method to implement: void actionPerformed( ActionEvent e) Register a listener : void AddActionListener(ActionEvent e) Constructors: JTextField(int numColumns) creates a JTextField object with numColumns columns that are visible. The initial string of the text field is null. JTextField(String text) creates a JTextField object and initializes the text to text, which is shown with enough columns to display the entire string. JTextField(String text, int numColumns) creates a JTextField object with numColumns columns and initial text, text. 1 Methods: void setText(String text) places text in the text field. String getText() returns the text in a text field. void setEditable(boolean editable) if editable is false the string in the text field is read-only, i.e., it cannot be changed. boolean isEditable() returns false if the text field is read-only. void setColums(int numColums) sets the number of columns that are displayed by the text field. int getColumns() returns the number of columns that are displayed by the text field. void setFont(Font font) set the font to font. void setHorizontalAlignment (int alignment) alignment is JTextField.LEFT, JTextField.RIGHT, and JTextField.CENTER....
View Full Document

Page1 / 6

textfields - CSc 2700: Lecture # 17 Textfields October 28,...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online