62,621
社区成员
发帖
与我相关
我的任务
分享import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class Test extends JFrame{
private JPanel panel;
private JTextPane textPane;
private JScrollPane scrollPane;
private JButton button;
private StringBuffer strBuffer = new StringBuffer();;
public Test(){
super("Test Add Text");
panel = new JPanel();
textPane = new JTextPane();
textPane.setText(new Date().toString() +": ");
textPane.setEditable(false);
scrollPane = new JScrollPane(textPane);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
button = new JButton("Add Text");
button.setPreferredSize(new Dimension(50, 25));
button.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
for(int i=1; i <2000;i++) {
strBuffer.append("1A2B3C4D5E6F7G8H9I0J\n");
}
String text = textPane.getText();
textPane.setText(text + strBuffer.toString());
}
}
);
panel.setLayout(new BorderLayout());
panel.add(scrollPane, BorderLayout.CENTER);
panel.add(button, BorderLayout.SOUTH);
setLayout(new BorderLayout());
add(panel, BorderLayout.CENTER);
setSize(500, 200);
setVisible(true);
}
public static void main(String args[]){
new Test();
}
}