JTextArea

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Animation implements ActionListener{

    JTextArea text;

    public static void main(String[] args) {
        Animation gui = new Animation();
        gui.go();
    }

    public void go() {
        JFrame frame = new JFrame();
        JPanel panel=new JPanel();

        JButton button = new JButton("冯小博牛逼吗??");
        button.addActionListener(this);  //听取本身时间 监听

        text=new JTextArea(10,20); //设定大小
        text.setVisible(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.setVisible(true);
    }
    public void actionPerformed(ActionEvent ev){
        text.append("冯小博牛逼 \n");
    }
}

猜你喜欢

转载自blog.csdn.net/m0_46243503/article/details/107615197