package pers.cc.Demo;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TextArea_1 implements ActionListener {
JTextArea text;
public static void main(String[] args){
TextArea_1 gui=new TextArea_1();
gui.go();
}
public void go(){
JFrame frame=new JFrame();
JPanel panel=new JPanel();
JButton button=new JButton("Just Click it");
button.addActionListener(this);
text=new JTextArea(10,20);
text.setLineWrap(true);
JScrollPane scroller=new JScrollPane(text);
scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
panel.add(scroller);
frame.getContentPane().add(BorderLayout.CENTER,panel);
frame.getContentPane().add(BorderLayout.SOUTH,button);
frame.setSize(350,300);
frame.setLocation(200,200);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent ev){
text.append("button clicked\n");
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/f59b27bf3f7f32e68a7cc231923139e8.png)