JAVA GUI in Netbeans to excute existing program

I need help getting a button that I created in NetBeans to start a program that I've already created. The program works find at the command line.

I'd like for it to be started via a button. How do I do that?
Who is Participating?
sciuriwareConnect With a Mentor Commented:

   /** (non-Javadoc)
    * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
    * @param a action event.
   public void actionPerformed(ActionEvent a)    // Must be public et al: see where you say "implements ActionListener"
      Object o = a.getSource();

      if(o == runButton)                                   // Always check if this is the firing button!!!
            new ExecThread().start();                  // The hard work will be in that class's run()
   } // = return

// Now you gotan asynchoneous execution and the screen can be updatged as well.


Starting one Java program from another program?

synchoneously by calling     MainClass.main(String[] commandline)  (fill in 'MainClass')

or  by exec(String[] commandvector);

And the place where to do it is in the public void actionPerformed() from that button.

bbcacAuthor Commented:
Now... I can execute the program by calling it from the actionPerformed method on the button... how do I check to see when the program is done?
bbcacAuthor Commented:
Also... how do I refersh the screen?

Here's the code in the action performed method

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        String args[]=new String[1];
        args[0] = "a";
        jLabel1.setText("Please wait while data is collected");


Even though I change the setText method, the text doesn't change until after I run the DataCollector.main() method. Which takes about 10 minutes.
The execution of the other program, the waitfor and the action to warn
the main program are all in that "ExecThread", that looks like:

public class ExecThread extends Thread

// The 'run' method does all the work.
// If done you can (e.g.) set a static boolean in the main program or so.
// I always call a method in the main program to show something on the screen etc.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.