Getting and setting the Flag variable in the stream

I am interacting with JNI, which allows me to use a fingerprint scanner. The code I wrote takes a scanned ByteBuffer, processed back by JNI, and turns it into a BufferedImage to save.

I cannot figure out how to wait for the validation flow to complete before the jlabel icon in my GUI tries to update. What would be the easiest way to do this?

What else do I need to add?

Edit:

//Scanner class Thread thread = new Thread() { public void run() { // [...] get ByteBuffer and Create Image code try { File out = new File("C:\\Users\\Desktop\\print.png"); ImageIO.write(padded, "png", out); // [???] set flag here } catch (IOException e) { e.printStackTrace(); } } }; thread.start(); return true; //Gui class private void btnScanPrintActionPerformed(java.awt.event.ActionEvent evt) { Scanner scanPrint = new Scanner(); boolean x = scanPrint.initDevice(); //Wait for the scanning thread to finish the Update the jLabel here to show //the fingerprint } 
+4
source share
2 answers

I'm not sure if you use Swing or Android for the user interface, but you want to notify the main thread of sending events about this (in swing this is called that way). You will start the scan thread, and then when you send the โ€œmessageโ€ to the EDT with the action you want to do with the button.

 Thread thread = new Thread(new Runnable(){ public void run(){ //scan SwingUtiltilies.invokeLater(new Runnable(){ //here you can update the the jlabel icon public void run(){ jlabel.setText("Completed"); } }); } }); 

There is no pending action in UI design because you always want the EDT to respond.

+3
source

at the end of the scan stream, use SwingUtilities.invokeLater() to update the gui with the scan results.

0
source

Source: https://habr.com/ru/post/1490477/


All Articles