40分帮我解答这个问题(在线等待)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class mytextfield extends JFrame implements ActionListener
{
private JLabel label=new JLabel("copy->paste");
private JTextField tf=new JTextField("we are so happy");
private JTextField tf2=new JTextField("",14);
private JButton copy=new JButton("copy");
private JButton paste=new JButton("paste");
private Container c;
public mytextfield(){
super("mytextfield test");
c=getContentPane();
c.setLayout(new FlowLayout(FlowLayout.CENTER));
c.add(label);
c.add(copy);
c.add(paste);
c.add(tf);
c.add(tf2);
setSize(300,200);
setVisible(true);
copy.addActionListener(this);
paste.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==copy)
tf.copy();
else if(e.getSource()==paste)
tf2.paste();
}
public static void main(String args[]){
mytextfield app=new mytextfield();
app.addWindowListener(new mywindowlistener());
}
}
程序编译和运行没有问题,但是我按意思程序复制的内容和我所要求的结果不一样,
结果应该是WE ARE SO HAPPY ,事实上结果却是程序里面的代码!