com.croftsoft.core.gui
Class ResetTextFieldKeyListener
java.lang.Object
java.awt.event.KeyAdapter
com.croftsoft.core.gui.ResetTextFieldKeyListener
- All Implemented Interfaces:
- KeyListener, EventListener
public final class ResetTextFieldKeyListener
- extends KeyAdapter
Used to reset a text field upon key press after user input error.
Example:
String text = textField.getText ( );
if ( "".equals ( text.trim ( ) ) )
{
textField.setBackground ( Color.red );
urlTextField.setText ( "data required" );
textField.addKeyListener (
new ResetTextFieldKeyListener ( textField, Color.white ) );
}
Upon key press detection, ResetTextFieldKeyListener will
- remove itself as a KeyListener from the TextField,
- set the TextField background to backgroundColor, and
- set the TextField to defaultText.
- Since:
- 2001-03-23
- Version:
- 2001-03-23
- Author:
- David W. Croft
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ResetTextFieldKeyListener
public ResetTextFieldKeyListener(TextField textField,
Color backgroundColor,
String defaultText)
ResetTextFieldKeyListener
public ResetTextFieldKeyListener(TextField textField,
Color backgroundColor)
- this ( textField, backgroundColor, "" );
keyPressed
public void keyPressed(KeyEvent keyEvent)
- Specified by:
keyPressed
in interface KeyListener
- Overrides:
keyPressed
in class KeyAdapter
CroftSoft Core Javadoc (2008-09-28 20:58:02)