首页 > 其他 > 详细

输入框事件监听TestFiled

时间:2021-08-11 23:44:27      阅读:24      评论:0      收藏:0      [点我收藏+]

输入框事件监听TestFiled

技术分享图片

package com.zishi.lesson02;
?
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
?
public class TestText01 {
   public static void main(String[] args) {
       //正常情况main只管启动
       new MyFrame();
  }
}
?
class MyFrame extends Frame{
   public MyFrame() {
       TextField textField = new TextField();
       add(textField);  //已经继承Frame,不需要再frame.add()
?
       //监听文本框输入的文字
       ActionListener myActionListenter3 = new MyActionListenter3();
       textField.addActionListener(myActionListenter3);
?
       //设置替换编码
       textField.setEchoChar(‘*‘);
?
?
       pack();
       setVisible(true);
  }
}
?
class MyActionListenter3 implements ActionListener{
?
   @Override
   public void actionPerformed(ActionEvent e) {
       //e.getSource(); //获得一些资源
       TextField textField=(TextField) e.getSource(); //获得一些资源,返回一个对象
       System.out.println(textField.getText());  //获得文本框中的内容
       textField.setText("");  //设置为空     区别null   ""
  }
}
?
?

技术分享图片

 

输入框事件监听TestFiled

原文:https://www.cnblogs.com/yizhifei/p/15130445.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!