import java.awt.*; import javax.swing.*; import java.awt.event.*; class EchoTextInput{ public static void main(String[] args){ JFrame frame = new JFrame("Echo Text Input"); Container pane = frame.getContentPane(); TextField input = new TextField("Edit this text then hit "); input.setFont(new Font("Sansserif",Font.ITALIC,24)); pane.add(input); Echo listener = new Echo(); input.addActionListener(listener); frame.setSize(200,200); frame.show(); frame.addWindowListener(new myWindowListener()); } } class myWindowListener extends WindowAdapter{ public void windowClosing(WindowEvent e){System.exit(0);} } class Echo implements ActionListener{ public void actionPerformed(ActionEvent e){ TextField source = (TextField)e.getSource(); String text = source.getText(); System.out.println(text); } }