import javax.swing.*;
import java.awt.event.*;
public class Freq extends JFrame implements ActionListener{
JButton jbutton=new JButton("请点击我");
JTextField jtextfield=new JTextField();
public Freq(){
setTitle("监听测试");
setSize(160,250);
this.getContentPane().setLayout(null);
jtextfield.setBounds(25,25,100,25);
jbutton.setBounds(25,75,100,25);
jbutton.addActionListener(this);
this.getContentPane().add(jtextfield);
this.getContentPane().add(jbutton);
}
public void actionPerformed(ActionEvent e){
jtextfield.setText(jbutton.getText());
}
public static void main(String[]args){
Freq x=new Freq();
x.setVisible(true);
x.setResizable(false);
}
}
温馨提示:答案为网友推荐,仅供参考