import java.util.* ; import java.io.* ; import java.awt.* ; import java.awt.event.* ; import javax.swing.* ; import javax.swing.event.* ; class TerminationListener implements WindowListener { public void windowActivated(WindowEvent e) {} public void windowClosed(WindowEvent e) {} public void windowClosing(WindowEvent e) { System.exit(0) ; } public void windowDeactivated(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowOpened(WindowEvent e) {} } class TextFieldPanel extends JPanel implements DocumentListener { public TextFieldPanel() { input = new JTextField(20) ; input.getDocument().addDocumentListener(this) ; add(input) ; display = new JTextField(20) ; display.setEditable(false) ; add(display) ; } public void changedUpdate(DocumentEvent evt) { } public void insertUpdate(DocumentEvent evt) { display.setText(input.getText()) ; } public void removeUpdate(DocumentEvent evt) { display.setText(input.getText()) ; } private JTextField input, display ; } public class TextFieldTest { public static void main(String [] args) { JFrame frame = new JFrame() ; frame.setTitle("TextField") ; frame.setSize(450, 300) ; frame.addWindowListener(new TerminationListener()) ; frame.getContentPane().add(new TextFieldPanel()) ; frame.setVisible(true) ; } }