You can, but the trick is to not slow down the firing of events, but to slow down how fast you process them:
KeyListener kl = new KeyListener() {
private long lastPressProcessed = 0;
@Override
public void keyPressed(KeyEvent e) {
if(System.currentTimeMillis() - lastPressProcessed > 500) {
//Do your work here...
lastPressProcessed = System.currentTimeMillis();
}
}
@Override
public void keyTyped(KeyEvent e) {}
@Override
public void keyReleased(KeyEvent e) { }
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…