0

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();
            }
        }
    }
Zephyr
  • 9,885
  • 4
  • 28
  • 63
Atif Aziz
  • 31
  • 6

1 Answers1

0
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(1), e -> System.out.println("Printed after 1 second from FX thread")));
timeline.play();

So this will pause the current working for 1 sec duration and will resume afterwards. For your case you can make this function to run for finite time and then resume as the resume button is clicked.

Follow this link for more details

Raza
  • 189
  • 1
  • 7