how to pause and resume a program like the pause/resume button on a player


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: how to pause and resume a program like the pause/resume button on a player

  1. #1
    Join Date
    Jul 2005
    Posts
    28

    how to pause and resume a program like the pause/resume button on a player

    Could somebody please suggest me how I can pause a program and then resume it like what the pause/resume buttons on a media player do?


    Thanks very much!

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    I guess you mean pausing some process then, - if the program waits for user action(s)
    it already in a "dormant" stage.
    You could have a button "Pause" that starts a thread, pauser, that does nothing but
    sleep, and join() that thread. And another button "Resume", that does a
    pauser.interrupt() call. In your run method's try/catch for InterruptedException you
    then start/resume the process by a call to an appropriate method and do a return
    from the run method.
    eschew obfuscation

  3. #3
    Join Date
    Jul 2005
    Posts
    28
    Thanks a lot, sjalle.

    Before I come to this step, I am now stuck on another problem.

    I have a main method, I let it run and I get a GUI interface, at this stage, I want it to wait until I press a "Start" button and then the program could start to run something, listen to the pause and resume interrrupt.

    I now made my progarm something like this:

    public static void main( String args[]){
    .....
    xx1.start();
    }
    .
    .
    .
    public void start(){
    try{
    wait();
    }catch(InterruptedException e){
    xx2.programRun());
    }
    }

    And I got the following exception:

    java.lang.reflect.InvocationTargetException:
    java.lang.IllegalMonitorStateException: current thread not owner
    at java.lang.Object.wait(Native Method).

    Could somebody suggest me on it please? Thanks!

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Hmm, I don't think you need a thread for that. Just a method that starts the
    processing (loop ?) and checks for the value value of a boolean (goOn ?) that
    is set to true/false at the click of your buttons. So your processing is started/
    continued in the Start buttons eventhandler that sets goOn=true and starts/continues
    the processing, and the Pause btn that sets goOn=false, which in turn will break the
    processing loop.
    eschew obfuscation

Similar Threads

  1. Pause and resume a download
    By troublesome in forum Java
    Replies: 0
    Last Post: 06-20-2005, 07:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center