importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;classTextAreaDemoextendsJFrame{privateJTextAreat1,t2;privateJButtoncopy,cut,append,clear,close;privateJPaneljp...
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( "Copy >>>" );
buttonhandle h1=new buttonhandle();
copy.addActionListener(h1);
cut.addActionListener(h1);
append.addActionListener(h1);
clear.addActionListener(h1);
close.addActionListener(h1);
jp1.add( copy );
jp1.add( cut );
jp1.add( append);
jp1.add( clear);
jp1.add(close);
t2 = new JTextArea( 10, 20 );
b.add( new JScrollPane( t2 ) );
setSize( 500, 300 );
show();
}
private class buttonhandle implements ActionListener {
public void actionPerformed( ActionEvent e ){
if(e.getSource()==copy)
t2.setText( t1.getSelectedText() );
else if(e.getSource()==cut)
{t1.cut();t2.cut();}
else if(e.getSource()==append)
t2.append(t1.getSelectedText() );
else if(e.getSource()==clear)
t2.setText("");
if(e.getSource()==close)
System.exit(0);
}
}
}
public class ZMJ{
public static void main( String args[] ){
TextAreaDemo app = new TextAreaDemo();
app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}
}
怎么加一个刷按按钮或其他类型的按钮
展开