Introduction
// Create a text field with some initial text JTextField textfield = new JTextField("Initial Text"); // Create a text field with some initial text and a default number of columns. // The number of columns controls the preferred width of the component; // each column is rougly the size of an M in the current font. int cols = 30; textfield = new JTextField("Initial Text", cols); // Listen for action events, which are fired when the user hits RETURN textfield.addActionListener(new MyActionListener()); class MyActionListener implements ActionListener { public void actionPerformed(ActionEvent evt) { JTextField textfield = (JTextField)evt.getSource(); process(textfield.getText()); } }