//已调试
import javax.swing.*;
import java.awt.*;
public class CopyFrame extends JFrame{
private JTextField tf1 = new JTextField(10);
private JTextField tf2 = new JTextField(10);;
public CopyFrame() {
JButton btnCopy = new JButton("copy to other text");
btnCopy.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
tf2.setText(tf1.getText());
}
});
setBounds(100,
100,
200,
300);
setLayout(new FlowLayout(FlowLayout.CENTER));
add(tf1);
add(btnCopy);
add(tf2);
setDefaultCloseOperation(EXIT_ON_CLOSE );
setVisible(true);
}
public static void main(String[] args) {
new CopyFrame();
}
}
温馨提示:内容为网友见解,仅供参考