JAVA图形程序·

来源:百度知道 编辑:UC知道 时间:2024/05/18 17:59:13
怎么编写一个图形用户程序,里面包括2个文本框,一个按钮。当用户单击按钮时,程序把一个文本框中当前的内容复制到另一个文本框中?
最好是application··

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;

public class CopyContentToAnother extends JFrame implements ActionListener{
JButton button;
JTextArea jtx,jtx2;
Container c;
JPanel p;

public CopyContentToAnother(){

c=this.getContentPane();

p= new JPanel();
jtx = new JTextArea(12,12);
jtx2 = new JTextArea(12,12);
button = new JButton("确定");
button.addActionListener(this);

p.add(jtx);
p.add(jtx2);
p.add(button);
this.add(p);
this.setSize(500, 400);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {

if(e.getSource() == button){
jtx2.setText(jtx.getText());
jtx.setT