Results 1 to 4 of 4
  1. #1
    2bGeek is offline Member
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Exclamation How to stop/pause running third party exe?

    I do need help as how do you actually stop the running application (same third party exe; that is executed earlier in the program.).. without stopping the whole GUI.
    the problem am having is that when application is running.. non of the buttons respond on the GUI. My code is as below:
    Java Code:
    try {
                    Runtime rt = Runtime.getRuntime();
                    File file = fc.getSelectedFile();         //defined earlier in code.
                    result = file.getPath();                     //defined earlier in code.
                    String command = "cmd /c clic c:\\mp3play.gd -i " + result;
                    Process pr = rt.exec(command);
                    BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    
                    String line=null;
    
                    while((line=input.readLine()) != null) {
                        System.out.println(line);
                    }
    
                    int exitVal = pr.waitFor();
                    System.out.println("Exited with error code "+exitVal);
    
                } catch(Exception e) {
                    System.out.println(e.toString());
                    e.printStackTrace();
                }
    When I execute, the whole GUI becomes irresponsive untill the application stops by it self.
    Thanks in advance!!

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    You're going to need to use some kind of threading here. Pay special attention to the tutorial Threading in Swing

  3. #3
    devunion is offline Member
    Join Date
    Jun 2008
    Posts
    56
    Rep Power
    0

    Default

    May be
    Java Code:
    Process.destroy();
    ?

    As mentioned above, you need to run another thread with timeout checking code before.
    Try Controls4J - Advanced Swing Components.

  4. #4
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Orange Dog is correct. You need multiple threads. On the surface, this sounds easy, but in practice, multi-threaded programming is where the fun (diffculty) and $ is.

    A simple approach, which might be sufficient here, would be to have your button press disable the button, spawn a new thread, which then enables that button when the thread completes. something like...

    Java Code:
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
         button.setEnabled(false);
    
          new Thread() {
             public void run() {
                ...all your code you were doign here...
    
                button.setEnabled(true);
             }
          }.start();
      }
    });

Similar Threads

  1. Running a third-party-library based application in j2me
    By nishantsuneja in forum CDC and Personal Profile
    Replies: 0
    Last Post: 02-08-2009, 10:39 PM
  2. Replies: 1
    Last Post: 12-07-2008, 06:50 PM
  3. pause until JFrame is closed.
    By Tamu in forum Advanced Java
    Replies: 8
    Last Post: 11-30-2008, 10:46 PM
  4. Need to hook up my jsp code to third party vendor
    By priya123 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-28-2008, 11:24 PM
  5. Help with Pause
    By trill in forum Java Applets
    Replies: 2
    Last Post: 09-28-2007, 09:50 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
  •