package cn.rushangw.lesson02;

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

public class TestText01 {
    public static void main(String[] args) {
        //启动
        new MyFrame();
    }
}


class MyFrame extends Frame{
    public MyFrame(){
        TextField textField = new TextField();
        add(textField);

        //监听文本框输入的东西
        textField.addActionListener(new MyActionListener());

        pack();
        setVisible(true);
    }
}

class MyActionListener implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        TextField field = (TextField) e.getSource();  //获得资源,获得一个对象
        System.out.println(field.getText());//获得文本框输入的文本
        field.setText("");

    }
}