Need guidance using threads for a barcode scanner application
Hello,
Thank you for any help you can provide!
I am writing a simple java mobile application that runs on a handheld motro=
la bar code scanner using java 1.4 (NSI CrEME CDC).
I used the motorola sample program to successfully run on the scanner. When=
the user presses the trigger, the laser scans and displays the item code i=
n a text area widget. BUT, the example is written such that it runs directl=
y on the the initial thread, as represented below:
public static void main(String argv[]){
(new J_ScanSample1()).go();
}
public synchronized void go(){
createDisplay();
while (!exiting){
if (!stopScanning)
{scanner.read(null, this);}
}
After googling, I seem to believe I need to create the GUI in a runnable ob=
ject, and then create the scanner background process in another runnable ob=
ject, but could someone briefly give an example how I would do this? I thin=
k I launch the GUI as shown below, but then do I just set the scanner proce=
ss in another runnable object? How does the GUI get updated after the scann=
er reads in data?
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ScannerApp().setVisible(true);
}
});
}