62,614
社区成员
发帖
与我相关
我的任务
分享
public class Copy extends Frame {
Button b;
TextField L, R;
public void display() {
Frame f = new Frame("复制");
f.setSize(300, 150);
f.setBackground(Color.lightGray);
f.setLayout(new FlowLayout());
L = new TextField(10);
R = new TextField(10);
b = new Button("复制");
f.add(L);
f.add(R);
f.add(b);
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
R.setText(L.getText());
}
});
f.setVisible(true);
}
public static void main(String[] args) {
(new Copy()).display();
}
}
import java.awt.*;
import java.awt.event.*;
public class Copy implements ActionListener {
Button b;
TextField L, R;
public void display() {
Frame f = new Frame("复制");
f.setSize(300, 150);
f.setBackground(Color.lightGray);
f.setLayout(new FlowLayout());
L = new TextField(10);
R = new TextField(10);
b = new Button("复制");
f.add(L);
f.add(R);
f.add(b);
b.addActionListener(this);// MyEclipse报错
f.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == b) {
// 把左边文本框的内容复制到右边的文本框中
R.setText(L.getText());
}
}
public static void main(String[] args) {
(new Copy()).display();
}
}