Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JAVA GUI in Netbeans to excute existing program

Posted on 2006-11-17
7
Medium Priority
?
236 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

715 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