I have created a Java Application which is a screen recorder. First I added functionality for Start and Stop recording but now asked to add PAUSE option too. I want to the entire working to stop when Pause is clicked and resume when clicked again. I am unable to use sleep because it requires time.
I have tried wait-notify logic. Can someone please guide me, how can I stop working of code until clicked again?
boolean paused;
//boolean paused=false;
@FXML
private void pauseRec(ActionEvent event) throws AWTException, InterruptedException
{
if (paused==false)
{
paused= true;
pauseRec.setText("Resume");
recordStateLabel.setText("Recording Paused");
synchronized(threadObject)
{
// Pause
try
{
threadObject.wait();
}
catch (InterruptedException e)
{
}
}
//rob.delay(10000);
}
else if(paused ==true)
{
paused=false;
pauseRec.setText("Pause");
recordStateLabel.setText("Recording..");
synchronized(threadObject)
{
threadObject.notify();
}
}
}