package copy.com;
 
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JButton;
 
public class copy extends JFrame{
   JButton b;
   JTextField L,R;
   public void display()
   {
     JPanel f=new JPanel(new GridLayout(1,2));
     f.setSize(300,100);
     f.setBackground(Color.lightGray);
 
     L=new JTextField();
     R=new JTextField();
     f.add(L);
     f.add(R);
     b=new JButton("复制");
 
     this.add(f);
     this.add(b,BorderLayout.SOUTH);
     this.setTitle("复制");
     this.setBounds(300,200,380,120);
     this.setDefaultCloseOperation(EXIT_ON_CLOSE);
     this.setVisible(true);
 
     b.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
       {
         String str=L.getText();  //读取左边字符
         R.setText(str);   //左边字符复制到右边
       }
     });
   }
 
   public static void main(String []args)
   {
     copy m=new copy();
     m.display();
   }
}运行结果:

    
    
    










