001 package util.swing; 002 003 import javax.swing.*; 004 import javax.swing.event.*; 005 import javax.swing.text.*; 006 007 /** 008 * A {@link JTextField} that writes its current content into a String referenced through an array. This is useful 009 * so that you will not need references to the <code>JTextField</code> in your code that might eventually lead 010 * to the text field being serialized which, in turn, might not work properly. 011 * 012 * <p><b>Note:</b> This class is not meant to be serialized!</p> 013 * 014 * @author Steffen Zschaler 015 * @version 2.0 28/07/1999 016 * @since v2.0 017 */ 018 public class JTextInput extends JTextField { 019 020 /** 021 * The currently referenced output observer. The current text of the input field can be found as the first 022 * element of the array. 023 * 024 * @serial This class is not meant to be serialized! 025 */ 026 protected String[] m_asOutput; 027 028 /** 029 * Create a new <code>JTextInput</code>. 030 * 031 * @param asOutput the output observer. The current text of the input field can be found as the first 032 * element of the array at any time. 033 * @param sInitial the initial value of the text field. 034 */ 035 public JTextInput(String[] asOutput, String sInitial) { 036 super(sInitial); 037 038 m_asOutput = asOutput; 039 040 getDocument().addDocumentListener(new DocumentListener() { 041 public void changedUpdate(DocumentEvent e) { 042 performUpdate(); 043 } 044 045 public void insertUpdate(DocumentEvent e) { 046 performUpdate(); 047 } 048 049 public void removeUpdate(DocumentEvent e) { 050 performUpdate(); 051 } 052 053 private void performUpdate() { 054 m_asOutput[0] = getText(); 055 } 056 }); 057 } 058 }