Solved

JAVA GUI in Netbeans to excute existing program

Posted on 2006-11-17
7
175 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

762 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

15 Experts available now in Live!

Get 1:1 Help Now