Swing键盘驱动
2016-11-28 22:21
134 查看
package com.dhy.swing.test; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.KeyStroke; public class BindKeyTest { JFrame jf=new JFrame("测试键盘绑定"); JTextArea jta=new JTextArea(5,30); JButton jb=new JButton("发送"); JTextField jtf=new JTextField(15); public void init(){ jf.add(jta); JPanel jp=new JPanel(); jp.add(jtf); jp.add(jb); jf.add(jp,BorderLayout.SOUTH); //发送消息的Action,Action是ActionListener的子接口 Action sendMsg=new AbstractAction(){ @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub jta.append(jtf.getText()+"\n"); jtf.setText(""); } }; //添加时间监听 jb.addActionListener(sendMsg); //将Ctrl+Enter键和"send"关联 jtf.getInputMap().put(KeyStroke.getKeyStroke('\n',java.awt.event.InputEvent.CTRL_MASK), "send"); //将"send"和sendMsg Action关联 jtf.getActionMap().put("send", sendMsg); jf.pack(); jf.setVisible(true); } public static void main(String [] args ){ new BindKeyTest().init(); } } ![这里写图片描述](http://img.blog.csdn.net/20161128222102782)
相关文章推荐
- 210板wince键盘驱动分析和移植
- S3C44B0X键盘的uClinux驱动
- hook键盘驱动中的分发函数实现键盘输入数据的拦截
- 驱动开发 键盘过滤驱动程序-- 传统的键盘过滤
- 键盘驱动组件事件
- Linux下的USB总线驱动(04)——USB键盘驱动 usbkbd.c
- 驱动笔记15 - 键盘过滤驱动学习笔记
- SWing的经典写法,了解事件驱动和内部类
- 新扬天电脑所配USB键盘功能键驱动问题注意事项
- 键盘驱动不兼容的问题及解决方案
- (转)支持 PS/2 与 USB 的键盘过滤驱动(可卸载)
- Linux 键盘驱动总体思路
- 过滤键盘驱动对象Kbdclass的所有设备对象
- Qt触摸屏、键盘的驱动
- Java Swing中的键盘事件处理
- serio总线------虚拟键盘驱动--键盘中断
- USB驱动——键盘,U盘
- Java Swing中的键盘事件处理
- 键盘驱动的原理
- Android 架构解析及驱动 键盘篇