输入框事件监听

 

e.getText返回的是一个Object对象,向下转型成TextField类的对象

 

 

public class TestText01 {
    public static void main(String[] args) {
        new  MyFrame();
        
    }
}
class MyFrame extends  Frame{

    public MyFrame(){
        TextField textField = new TextField();
        this.add(textField);
        textField.addActionListener(new MyActionListener02());
        setVisible(true);
        setSize(200,200);
    }
}
class MyActionListener02 implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        TextField Field=(TextField) e.getSource();
        System.out.println(Field.getText());
    }
}

 

posted on 2022-08-03 22:06  大风吹过12138  阅读(33)  评论(0)    收藏  举报

导航