I'm trying to get my head around SwingWorker, I'm creating a fairly simple vending machine application. And I've identified the following use cases
Start: Message = "MACHINE READY"
Keypad pressed (change>0 && prodcode.length<=2): append to product code, update message with Balance: xx Product: x
Enter pressed (change>0 && code.length>1): check money inserted, check code is valid, check slot for item, check correct change
update item tray with item, reduce slot count by one, update message to Balance: xx Product:
Clear pressed: reset change to 0 prod code to blank and message to "MACHINE READY"
Return change pressed: set change tray to current change for 3 seconds, set change to 0 prod code to blank, update message to "MACHINE READY"
(a)Invalid code: Message = "Invalid code" wait for 3 seconds, update message to Balance: xx Product:
(b)Incorrect change (change>0): Message = "Incorrect change" wait for 3 seconds, update message to Balance: xx Product:
(c)Incorrect change (change==0): Message = "Insert money" wait for 3 seconds, back to start message
(d)Empty slot: Message = "Slot empty" 3 seconds, update message to Balance: xx Product:
Here's the UI
I'm finding it hard identifying what kind of SwingWorker tasks I'm going to need to achieve all this, can anyone help?
Ok then perhaps I'm just getting confused with how to get my GUI to respond to my commands in general? I've written code which as far as I am aware should work, but when I click on any of the buttons the UI becomes unresponsive. The tasks its doing shouldn't be that labour intensive so I'm a little bit stuck (SwingWorker would probably be overkill from what you're saying).
I think I've included all of the important snippets of code, I must be missing something very fundamental?
Are you sure it's the call to setMessage that freezes your UI, and not the code you omitted at line 33? Can you post that part as well? And the code in vMachine.giveChange(), as that's also a possible time consuming call.