java 界面刷新按钮

来源:百度知道 编辑:UC知道 时间:2024/09/25 12:32:38
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class TextAreaDemo extends JFrame {
private JTextArea t1, t2;
private JButton copy,cut,append,clear,close;
private JPanel jp1;
public TextAreaDemo()
{
super( "TextArea Demo" );
javax.swing.Box b = javax.swing.Box.createHorizontalBox();
Container c = getContentPane();
jp1=new JPanel();
c.add( b );
c.add(jp1,"North");
String s = " 1\n" +
"2。\n" +
"3。\n" +
"4。\n"+
"5。\n";

t1 = new JTextArea( s, 30, 20 );
b.add( new JScrollPane( t1 ) );

close=new JButton( "close" );
clear=new JButton( "clear" );
cut=new JButton( "cut" );
append=new JButton( "append" );
copy = new JButton( "Co

随便来个一般的按钮,只不过要刷新就将他的点击事件改成updateUI或者先将界面invalidate再validate都可以刷新界面。

随便加一个 button就是了 给他添加一个按键监听器 用updateUI()更新 或 用repaint() 重画