My program has a SimController class which holds most of the logic for executing a simulation run. Before, it was in the method startSimulation(), which the constructor ran. The first thing this code does is fire a JOptionPane message. Upon clicking OK, the code executes. We now want to control when the startSimulation() method runs by adding a Start Simulation JButton to the main frame.
So, I added a Start button to the frame, registered it with the "ButtonListener" in the JFrame class, and declared that when the Start button is pressed, it should fire the simController object's startSimulation() method. This appears to work up to a point.
The JOptionPane still comes up, but once you click OK, it hangs up until the simulation run is complete. The real time updating of the various components (mostly text fields) doesn't work, and the program basically freezes until the run is over. If we revert to the old way (having the constructor automatically execute startSimulation(), it works fine.
Does anyone know what the problem might be? Thanks for any help you can give!!
P.S. The program runs in a single thread. Might this be the problem? I would prefer to keep it a single thread if possible.
Because all drawing and event-listening methods are executed in the same thread, a slow event-listener method can make the program seem unresponsive and slow to repaint itself. If you need to perform some lengthy operation as the result of an event, do it by starting up another thread