import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class TextFieldTest extends JFrame {
    private JTextField copyFrom;
    private JTextField copyTo;
    private JLabel label = new JLabel("Press return to copy the text");
    private JButton clearButton = new JButton("Clear all the text fields");
    public TextFieldTest() {
	getContentPane().setLayout(new GridLayout(4,1));
	copyFrom = new JTextField("Type here");
	copyTo = new JTextField();
        getContentPane().add(copyFrom);
	getContentPane().add(label);
	getContentPane().add(copyTo);
	getContentPane().add(clearButton);
	
	copyFrom.addActionListener(new TextListener());
	clearButton.addActionListener(new ButtonListener());
    }
    
    class ButtonListener implements ActionListener {
	public void actionPerformed(ActionEvent e) {
	    // clear the text field
	    copyFrom.setText("");
	    copyTo.setText("");
	}
    }
    
    class TextListener implements ActionListener {
	public void actionPerformed(ActionEvent e) {
	    // get the text form the text field and copy to the other
	    String text = copyFrom.getText();
	    copyTo.setText(text);
	}
    }
    
      public static void main(String[] args) {
        TextFieldTest f = new TextFieldTest();
	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	f.pack();
	f.setVisible(true);
    }
}
	
