[java]ActionEvent事件:获取输入字符串的长度
来源:互联网 发布:淘宝宝贝模板编辑软件 编辑:程序博客网 时间:2024/05/01 12:46
代码:
Example9_7.javapublic class Example9_7{public static void main(String args[]){WindowActionEvent win= new WindowActionEvent();PoliceListen police = new PoliceListen();//创建监视器win.setMyCommandListener(police);win.setBounds(100,100,460,360);win.setTitle("处理ActionEvent事件");}}WindowActionEvent.javaimport java.awt.*;import javax.swing.*;public class WindowActionEvent extends JFrame{JTextField inputText;JTextArea textShow;JButton button;MyCommandListener listener;public WindowActionEvent(){init();setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}void init(){setLayout(new FlowLayout());inputText = new JTextField(10);button = new JButton("确定");textShow=new JTextArea(9,30);add(inputText);add(button);add(new JScrollPane(textShow));}void setMyCommandListener(MyCommandListener listener){this.listener=listener;listener.setJTextField(inputText);listener.setJTextArea(textShow);inputText.addActionListener(listener);button.addActionListener(listener);}}MyCommandListener.javaimport javax.swing.*;import java.awt.event.*;interface MyCommandListener extends ActionListener{public void setJTextField(JTextField text);public void setJTextArea(JTextArea area);}PoliceListen.javaimport java.awt.event.*;import javax.swing.*;public class PoliceListen implements MyCommandListener{JTextField textInput;JTextArea textShow;public void setJTextField (JTextField text){textInput=text;}public void setJTextArea(JTextArea area){textShow=area;}public void actionPerformed(ActionEvent e){String str=textInput.getText();textShow.append(str+"的长度:"+str.length()+"\n");}}
运行截图:
- [java]ActionEvent事件:获取输入字符串的长度
- java的ActionEvent事件
- Java文本框上的ActionEvent事件
- [Java] ActionEvent 事件处理
- Java-ActionEvent事件
- ActionEvent事件
- java学习:AWT组件和事件处理的笔记(1)--文本框上的ActionEvent事件
- 获取字符串的长度!
- 获取字符串的长度
- 获取字符串的长度
- 字符串长度的获取
- 任意长度的字符串输入
- 任意长度的字符串输入
- 任意长度的字符串输入
- java按照字节长度获取字符串长度
- [C]获取用户输入字符串------在不知道用户输入长度的时候
- java获取用户输入的字符串!...
- java获取用户输入的字符串!
- 杭电ACM HDU 2502 月之数
- Percona Monitoring Plugins 1.0.2 发布
- 内部类和匿名内部类
- 黑马程序员——网络编程TCP
- 教你如何申请个人域名及用免费的虚拟主机
- [java]ActionEvent事件:获取输入字符串的长度
- 黑马程序员之TCP
- JAVA NIO 简介
- 关于颜色直方图和反向投影的一些理解
- 几何题-求圆柱最大体积
- onunload调用下面js函数
- winPhone开启摄像头
- 黑马程序员——正则表达式
- 全球50个最有特色网站