import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
public class TextAreaApp extends JFrame implements DocumentListener
{
private JTextArea baseText,copyText;
private JScrollPane sp1,sp2;
public TextAreaApp()
{
setTitle("多行文本框的应用");
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container cp=getContentPane();
cp.setLayout(new FlowLayout());
baseText=new JTextArea(8,6);
copyText=new JTextArea(8,6);
baseText.setLineWrap(true);
copyText.setLineWrap(true);
sp1=new JScrollPane(baseText);
sp1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
cp.add(sp1);
sp2=new JScrollPane(copyText);
sp2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
cp.add(sp2);
baseText.getDocument().addDocumentListener(this);
setSize(240,200);
}
public void insertUpdate(DocumentEvent e)
{
copyText.setText(baseText.getText());
}
public void removeUpdate(DocumentEvent e)
{
copyText.setText(baseText.getText());
}
public void changedUpdate(DocumentEvent e)
{
copyText.setText(baseText.getText());
}
public static void main(String[] args)
{
TextAreaApp frame=new TextAreaApp();
frame.show();
}
}



