com.croftsoft.core.gui
Class ResetTextFieldKeyListener

java.lang.Object
  extended by java.awt.event.KeyAdapter
      extended by 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

  1. remove itself as a KeyListener from the TextField,
  2. set the TextField background to backgroundColor, and
  3. set the TextField to defaultText.

Since:
2001-03-23
Version:
2001-03-23
Author:
David W. Croft

Constructor Summary
ResetTextFieldKeyListener(TextField textField, Color backgroundColor)
          this ( textField, backgroundColor, "" );
ResetTextFieldKeyListener(TextField textField, Color backgroundColor, String defaultText)
           
 
Method Summary
 void keyPressed(KeyEvent keyEvent)
           
 
Methods inherited from class java.awt.event.KeyAdapter
keyReleased, keyTyped
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResetTextFieldKeyListener

public ResetTextFieldKeyListener(TextField textField,
                                 Color backgroundColor,
                                 String defaultText)

ResetTextFieldKeyListener

public ResetTextFieldKeyListener(TextField textField,
                                 Color backgroundColor)
this ( textField, backgroundColor, "" );

Method Detail

keyPressed

public void keyPressed(KeyEvent keyEvent)
Specified by:
keyPressed in interface KeyListener
Overrides:
keyPressed in class KeyAdapter

CroftSoft Javadoc

CroftSoft Core Javadoc (2008-09-28 20:58:02)