Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 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); } } |
Output: