I'm working on some coursework and this is a small part of it which I thought would be a good idea to implement.
I have two classes, Simulator and SimulatorView, the latter displays the GUI and the backend is run from the former. I'm passing the current instance of Simulator to SimulatorView. The reason for this is because I have a JMenu with JMenuItem's in it which will invoke methods on Simulator. Obviously the events are passed to actionPerformed() which is carried out in the dispatch thread. So if I run the application and then click on File > Run it will then halt the program until Simulator has finished and then display the final output. As it's a simulation of a real life scenario the simulation goes through a set number of states and usually you can watch it carry out through each state but as the action is thrown into the dispatch thread it'll halt.
Does this mean I have to use Thread and would it be easy to implement? My main problem is implementing everything because I have many options in the GUI and I need the simulation to run no matter what else I do. In the actionPerformed() method I have if else statements just checking what JMenuItem was pressed and then carrying out the necessary action.
Should I use Thread? Or Timer? Or (1.6 will implement it) SwingWorker? I've never implemented threads so I'm a bit stuck at the moment on how to implement it correctly.
Any help would be appreciated but don't give me big hints as it is for coursework


LinkBack URL
About LinkBacks
Reply With Quote