0
点赞
收藏
分享

微信扫一扫

左边窗口内容复制到右边窗口--简单

mjjackey 2022-06-08 阅读 55
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();
  }
}

运行结果:

 

左边窗口内容复制到右边窗口--简单_java

 


举报

相关推荐

0 条评论