package test1;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class test2 extends JFrame implements ActionListener{

//定义我需要的组件
JButton jb;
JLabel jl;
JTextField jtf;

public static void main(String[] args) {
test2 t2 = new test2();
}

//构造器
public test2(){
//创建组件
jtf = new JTextField(10);
jl = new JLabel();
jb = new JButton("OK");

//设置布局管理
this.setLayout(new GridLayout(3, 1));

//将组件加入到JFrame
this.add(jtf,BorderLayout.NORTH);
this.add(jl,BorderLayout.CENTER);
this.add(jb,BorderLayout.SOUTH);

//注册监听
jb.addActionListener(this);

//设置大小和初始位置
this.setSize(200, 300);
this.setLocation(200, 200);
this.setVisible(true);
}

//事件处理的方法
public void actionPerformed(ActionEvent e) {
String s = jtf.getText();
jl.setText(s);
}

}