Getting input from barcode scanner internally without textbox

前端 未结 3 1966
时光说笑
时光说笑 2020-12-13 11:17

I have a barcode scanner and in my java application I have to bring a popup to display all the information associated with the barcode from database when the product is scan

3条回答
  •  被撕碎了的回忆
    2020-12-13 12:09

    Since barcode scanner is just a device which sends keycodes and ENTER after reading of each barcode, I'd use a key listener.

    final Frame frame = new Frame();
    frame.setVisible(true);
    
    frame.addKeyListener(new KeyAdapter() {
    
        @Override
        public void keyReleased(KeyEvent e) {
            if(e.getKeyCode() == KeyEvent.VK_ENTER) {
                // your code is scanned and you can access it using frame.getBarCode()
                // now clean the bar code so the next one can be read
                frame.setBarCode(new String());
            } else {
                // some character has been read, append it to your "barcode cache"
                frame.setBarCode(frame.getBarCode() + e.getKeyChar());
            }
        }
    
    });
    

提交回复
热议问题