package java1; //使用时这个改成你的包名即可
//文本区 JTextArea
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class Areatext extends JFrame implements ActionListener{
JTextArea txt1Area = new JTextArea(7,35);
JTextField txt2Field = new JTextField(35);
String string = "窗外飘起蒙蒙小雨,
平添一夜寒意,"+
"
多少的思绪藏在心底";
public Areatext() {
setSize(400,300);
setVisible(true);
setTitle("文本组件实例");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());
txt1Area.setText(string);
add(txt1Area);
add(txt2Field);
validate();
txt2Field.addActionListener(this);//把文本框设置为监听对象
}
public void actionPerformed(ActionEvent e)
{
String string1 = txt2Field.getText();
txt1Area.append("
"+string1);
}
}
public class JText {
public static void main(String[] args) {
new Areatext();
}
}