Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SimulationThread extends Thread
- public void run()
- while (isRunning())
- synchronized (this)
- while (isPaused())
- try this.wait()
- doCalculations()
- doRendering() // more precisely invoke the repaint() method
- ******************************************************
- ............
- public void onUnPauseButtonPress()
- synchronized (Simulation.getSimulationThread())
- Simulation.getSimulationThread().notify();
- ******************************************************
- also be aware that the doCalculations() and the paintComponent() of the panel
- need to be synchronized (ideally with the panel object) because paintComponent()
- is actually called in the swing thread. you just call repaint() and then swing
- will call paintComponent in its own thread. if not synchronized the data could
- change half way through the rendering of a frame.
Add Comment
Please, Sign In to add comment