Add Action Listener To JTextField In Java

Chapter: Action Listener Last Updated: 08-08-2016 18:59:00 UTC

Program:

            /* ............... START ............... */
                
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class JavaJTextFieldActionListner extends JFrame {

	JTextField text = new JTextField("Press Return", 40);

	public JavaJTextFieldActionListner() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		text.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.out.println("Text=" + text.getText());
			}
		});

		getContentPane().add(text, "Center");
		pack();
	}

	public static void main(String[] args) {
		new JavaJTextFieldActionListner().setVisible(true);
	}
}
                /* ............... END ............... */
        

Output


Add Action Listener To JTextField In Java

Tags

Add Action Listener To JTextField, Java, ActionListener

Similar Programs Chapter Last Updated
Action Listener To JComboBox In Java Action Listener 22-09-2018
Get Event Source From ActionEvent Swing Java Action Listener 08-08-2016
ActionListener And Action Class Level Variable Swing Event Action Listener 08-08-2016
ActionListener Inner Class To Handle Event In Java Action Listener 28-07-2016
ActionListener Event Source In Java ActionPerformed Method Action Listener 28-07-2016
ActionListener Handling An Action In Java Action Listener 28-07-2016

1