Created
May 24, 2016 07:09
-
-
Save sarxos/a53255d60745e182de87c3bb81d8a242 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void actionPerformed(..) { | |
| Thread t = new Thread(new Runnable() { | |
| public void run() { | |
| // capture qr, this will not block because it's in thread, | |
| // do all long running/blocking operations here, in this | |
| // thread | |
| final String qr = captureQrCode(); | |
| // schedule swing update when edt is ready to be used, | |
| // this will bring you back to the edt (and blocking world), | |
| // but since this is easy operation, gui should not freez | |
| SwingUtilities.invokeLater(new Runnable() { | |
| public void run() { | |
| doSomethingWithQrCode(qr); | |
| } | |
| }); | |
| } | |
| }); | |
| t.setDaemon(true); | |
| t.start(); | |
| } | |
| void doSomethingWithQrCode(String qr) { | |
| // do something with QR code, update gui, this should | |
| // be non-blocking and fast operation, otherwise gui | |
| // will be freezing | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment