JAVA程序全局键盘监听事件
// 注册应用程序全局键盘事件, 所有的键盘事件都会被此事件监听器处理.
Toolkit tk = Toolkit.getDefaultToolkit();
tk.addAWTEventListener(new MyAWTEventListener(), AWTEvent.KEY_EVENT_MASK);
class MyAWTEventListener implements AWTEventListener {
private boolean controlPressed = false;
private boolean cPressed = false;
@Override
public void eventDispatched(AWTEvent event) {
if (event.getClass() == KeyEvent.class) {
// 被处理的事件是键盘事件.
KeyEvent keyEvent = (KeyEvent) event;
if (keyEvent.getID() == KeyEvent.KEY_PRESSED) {
keyPressed(keyEvent);
} else if (keyEvent.getID() == KeyEvent.KEY_RELEASED) {
keyReleased(keyEvent);
}
}
}
private void keyPressed(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.VK_CONTROL) {
controlPressed = true;
} else if (event.getKeyCode() == KeyEvent.VK_C) {
cPressed = true;
}
if (controlPressed && cPressed) {
&nbs
相关文档:
在使用队列中,我们一般都会使用循环队列以保证性能
package com.yz.myqueue;
public class Queue {
private Integer size;
private Integer front;
private Integer rear;
private Object[] datas;
public Queue(int size){
this.size=size;
this.front=-1;
this.rear=-1;
datas=new Object[size] ......
总结一:
Java IO的一般使用原则:
一、按数据来源(去向)分类:
1、是文件: FileInputStream, FileOutputStream, FileReader, FileWriter
2、是byte[]:ByteArrayInputStream, ByteArrayOutputStream
3、是Char[]: CharArrayReader, CharArrayWriter
4、是String: StringBufferInputStream, StringReader, StringW ......
package test;
import java.io.File;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack ......
boolean java.lang.Object.equals(Object obj)
Indicates whether some other
object is "equal to" this one.
The equals method implements an
equivalence relation on non-null object references:
It is reflexive: for
any non-null reference value x, x.equals(x) should return true.
It ......