输入框事件监听

 

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   大风吹过12138  阅读(30)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
点击右上角即可分享
微信分享提示