Java swing 如何实现双击Shift呢?
- startTimeField_3.addKeyListener(new KeyListener() {
- private long lastTimeMillSencond;
- @Override
- public void keyTyped(KeyEvent e) {
- }
- @Override
- public void keyReleased(KeyEvent e) {
- }
- @Override
- public void keyPressed(KeyEvent e) {
- if(e.isShiftDown()){
- if(lastTimeMillSencond==0){
- lastTimeMillSencond=System.currentTimeMillis();
- }else{
- long currentTime=System.currentTimeMillis();
- if(currentTime-lastTimeMillSencond<1000){
- System.out.println("双击Shift");
- lastTimeMillSencond=0;
- }else{
- lastTimeMillSencond=System.currentTimeMillis();
- }
- }
- }
- }
- });
下面的是错误的:
会导致:连续按下Shift 3次,会造成两次双击Shift