简体   繁体   English

具有Java swing的USB条形码扫描仪

[英]USB Barcode Scanner with Java swing

I have a Zebex Z-3100 CCD Scanner, which reads barcodes pretty neatly. 我有一台Zebex Z-3100 CCD扫描仪,它可以整齐地读取条形码。

What I'm trying to do is to make a java program that can handle the barcodes it reads, and so far I have managed to do it quite allright. 我正在尝试做的是制作一个可以处理读取的条形码的Java程序,到目前为止,我已经设法做到了。

What I'm struggeling with is to make the java program listen to the barcodes without marking the console / textarea(swing). 我正在努力的是使Java程序监听条形码而不标记控制台/ textarea(swing)。

When I start the program (swing) - and scan the code, it works, but when I use the keypad (which I have implemeted in swing) and press "Clear", it has touched the button "Clear" last, and the textfield is no longer outputting the barcodes that are read. 当我启动程序(摆动)并扫描代码时,它可以工作,但是当我使用键盘(已实现摆动)并按“清除”时,它最后触摸了“清除”按钮,并且触摸了文本字段不再输出读取的条形码。

I tried to solve this by making a seperat thread which only listens to 我试图通过制作一个单独的线程来解决这个问题

" Scanner sc = new Scanner(System.in); ", Scanner sc = new Scanner(System.in); ”,

but when I have clicked the button "Clear" it no longer has neither console nor the textfield marked, and no code is read by the program.. 但是当我单击“清除”按钮时,它既没有控制台也没有标记文本字段,并且程序没有读取任何代码。

Does anybody know an easy way to make the program allways listen to the scanner? 有人知道让程序始终监听扫描仪的简便方法吗?

The scanner seems to work like a keyboard -> numbers+enter (eg 41231 -> enter) 扫描仪的工作方式就像是键盘->数字+输入(例如41231->输入)

I'm not sure what part of the code to link, but I'll link code if someone needs/requests it! 我不确定要链接的代码的哪一部分,但是如果有人需要/请求,我将链接代码!

Thank you so much! 非常感谢!

EDIT When I mark the console/textarea it will read codes again. 编辑当我标记控制台/文本区域时,它将再次读取代码。 The only part I'm not sure how to do - is to make it listen to the barcode scanner "24/7"! 我不确定该怎么做的唯一部分-是让它收听条形码扫描仪“ 24/7”!

You problem is a simple focus issue. 您的问题是一个简单的焦点问题。 When you click the "clear" button, it now has keyboard focus, instead, you want to give focus back to the JTextField 当您单击“清除”按钮时,它现在具有键盘焦点,而您想将焦点返回给JTextField

When you click the "clear" button call requestFocusInWindow on the JTextField to move keyboard focus back to it 当您单击“清除”按钮时,请调用JTextField上的requestFocusInWindow将键盘焦点移回它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM