Solved

JAVA GUI in Netbeans to excute existing program

Posted on 2006-11-17
7
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

751 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