无需文本框即可在内部从条形码扫描仪获取输入 [英] Getting input from barcode scanner internally without textbox

查看:102
本文介绍了无需文本框即可在内部从条形码扫描仪获取输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个条形码扫描仪,在我的java应用程序中,当使用条形码扫描产品时,我必须带一个弹出窗口显示与数据库条形码相关的所有信息。我没有关于应用程序的文本框我必须在内部处理这个部分。我该怎么做呢 ?有什么建议吗?我正在使用swing for UI。

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 scanned using barcode. I have no textbox on the application I have to handle this part internally. How do I do this ? any suggestion ? I am using swing for UI.

编辑

条码扫描器是USB。如果我们扫描某些内容,它会将结果输出到具有焦点的文本框中。但我打开的页面上没有文本框。我可以使用一些隐藏的文本框并在那里读取值吗?

Barcode scanner is USB one. If we scan something it will output the result into the textbox which has focus. But I have no textbox working on the page opened. Can i work with some hidden textbox and read the value there ?

推荐答案

因为条形码扫描器只是一个发送密钥代码和ENTER的设备在读完每个条形码后,我会使用一个关键的监听器。

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());
        }
    }

});

这篇关于无需文本框即可在内部从条形码扫描仪获取输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆