Solved

JAVA GUI in Netbeans to excute existing program

Posted on 2006-11-17
7
188 Views
Last Modified: 2006-12-25
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?
0
Comment
Question by:bbcac
  • 3
  • 2
7 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 17967056
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.

;JOOP!
0
 

Author Comment

by:bbcac
ID: 17967483
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?
0
 

Author Comment

by:bbcac
ID: 17968036
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");
        DataCollector.main(args);
       
        startDoneListener();
       
    }  

////////////////////////////////////////

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.
0
 
LVL 24

Accepted Solution

by:
sciuriware earned 500 total points
ID: 17968777
No:

   /** (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.

;JOOP!

0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17968806
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.

;JOOP!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now