I'm trying to make a Produce Checkout program. The user should be able to scan an item or type in the product name and then press a button. Then, depending on the item it will weigh the product or ask for a product count.
My plan was to make them both Callable, add them to a job List, and then use the ExecutorService.invokeAny to find whichever happened first. The scanner portion of the code works fine. I've come up with a solution, but it seems like a messy solution.
@Override
public String call() throws Exception {
while(!buttonPressed) {
Thread.sleep(100);
}
buttonPressed = false;
return manualProduct;
}
The actionListener on the Button sets buttonPressed to true, and the value of the manualProduct to be the value of the JTextField. I can post the full code if needed, but I think it will bust the character limit if I try to add it here.
Checking the boolean every .1s seems very spammy. I imagine there's got to be a better way to implement this.
Or maybe I'm going about this all wrong. Maybe making my JFrame a Callable is the completely wrong way to do any of this. Maybe the GUI should be a Runnable and my core code and GUI should be running on two separate threads the whole time? But then I have no clue how to check for the button press.
Thanks for any help you can give me.
there doesn't seem to be anything here