[CODE]import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MyButtonDemo extends JFrame implements ActionListener
{
JTextArea text1JTA,text2JTA;
JScrollPane text2JSP;
JButton button;
MyButtonDemo()
{
super("MyButtonDemo");
button = new JButton("确定");
text1JTA = new JTextArea(10,10);
text2JTA = new JTextArea(10,10);
text2JTA.setEditable(false);
text2JSP = new JScrollPane(text2JTA);
JPanel workJP = new JPanel();
workJP.add(text1JTA);
workJP.add(text2JSP);
workJP.add(button);
button.addActionListener(this);
setContentPane(workJP);
setSize(600, 400);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button)
{
String selectedText = text1JTA.getSelectedText();
if(selectedText != null)
text2JTA.append(selectedText + "\n");
}
}
public static void main(String [] args)
{
MyButtonDemo b = new MyButtonDemo();
}
}[/CODE]