Java DocumentListener implement
import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; public class Main extends JFrame { public Main() { super("JButton"); setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(new FlowLayout()); JLabel nameLabel = new JLabel("Name:"); JTextField name = new JTextField(20); name.getDocument().addDocumentListener(new DocumentListener() { @Override//w w w.j a v a 2 s .c om public void insertUpdate(DocumentEvent e) { System.out.println(e); } @Override public void removeUpdate(DocumentEvent e) { System.out.println(e); } @Override public void changedUpdate(DocumentEvent e) { System.out.println(e); } }); getContentPane().add(nameLabel); getContentPane().add(name); } public static void main(String[] args) { Main frame = new Main(); frame.pack(); frame.setVisible(true); } }