Solved

JAVA GUI in Netbeans to excute existing program

Posted on 2006-11-17
7
197 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping3 challenge 14 79
servlet doXXX methods 3 49
factorial example 4 39
Error in @AspectJ Based AOP with Spring 2 13
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

776 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