swing 文本框判断是否输入完成

java swing 文本框判断是否输入完成

inputQRTextArea.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 (EventHWUtil.isJustShiftDown(e)) {//双击Shift
                    if (lastTimeMillSencond == 0) {
		                lastTimeMillSencond = System.currentTimeMillis();
		            } else {
		                long currentTime = System.currentTimeMillis();
		                if (MenuUtil2.isDoubleClick(currentTime - lastTimeMillSencond )) {
		                    genQRbutton.doClick(); 
		                    lastTimeMillSencond = 0;
		                } else {
		                    lastTimeMillSencond = System.currentTimeMillis();
		                }
		            }
                } else {//输入完成之后生成二维码
                    if (timer == null) {
                        timer = new Timer();
                    }
                    if (null != task) {
//                        System.out.println(222);
                        task.cancel();
                        task = null;
                    }

                    if (task == null) {
//                        System.out.println(111);
                        task = new TextBoxTask(QRCodePanel.this);
                        timer.schedule(task, INPUT_WAIT_SECOND * 1000);
                    }
                }
            }
		});

要执行的任务:

import com.swing.component.QRCodePanel;

/**
 * Created by 黄威 on 16/11/2016.<br >
 */
public class TextBoxTask extends java.util.TimerTask {
    private QRCodePanel qrCodePanel;

    public TextBoxTask(QRCodePanel qrCodePanel) {
        super();
        this.qrCodePanel = qrCodePanel;
    }

    @Override
    public void run() {
        //输入完成之后生成二维码
        System.out.println("$$$$$");
        this.qrCodePanel.generateQRAction(false);
    }
}

 参考我的另外一篇博客:http://hw1287789687.iteye.com/blog/2323017

猜你喜欢

转载自hw1287789687.iteye.com/blog/2338245
今日推荐