日期:2014-05-20 浏览次数:20840 次
package area; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.event.CaretEvent; import javax.swing.event.CaretListener; public class Main{ static JTextArea area1; static JTextArea area2; public static void main(String args[]){ JFrame f = new JFrame(); initial(); JPanel p = new JPanel(); f.getContentPane().add(p); p.setLayout(null); p.add(area1); area1.setBounds(0, 0, 300, 250); p.add(area2); area2.setBounds(0, 260, 300, 250); f.setSize(300, 600); f.setVisible(true); } public static void initial(){ area1 = new JTextArea(); area2 = new JTextArea(); area1.addCaretListener(new CaretListener(){ public void caretUpdate(CaretEvent arg0) { area2.setText(area1.getText()); } }); } }