wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Launching an app within in app? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Launching an app within in app?" Watch "Launching an app within in app?" New topic
Author

Launching an app within in app?

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
I have create an application for our Costing department and also
have created a separate application for our order entry department.
Each application has it's own main method.
What I am trying to do , is within the Costing application, I would
like the user to be able to click on a button, and launch the
order entry application.
I tried just creating an object of the order entry class on an actionPerformed event in the costing app, but nothing came up.
Is there something special I need to be doing?
Here is the class with the main method in it for the order entry app...

Thanks for any help!
Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

You can do it 1 of 3 ways:
1. If you want the CVOrderEntry executing as a separate process (i.e. in a separate JVM), then use one of the java.lang.Runtime.exec() methods to kick off another process.
2. If you want them to execute in the same JVM, then as long as your other class has access to this CVOrderEntry object you can just call it directly. But, since you have some initialization stuff in your main(), you will have to do that as well in the calling class.
3. You could also use reflection and call the main() method in your CVOrderEntry class. Check out the java.lang.reflect package.
Options 1 or 2 are the easiest.

Hope it helps!
Barry
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Don't know why she would need to use reflection to call main() in the other class; main is just an ordinary method, and she could just call it if that's what would do the job.


[Jess in Action][AskingGoodQuestions]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

The only thing to watch out for when calling the main method directly is what happens when the window closes. If both applications call System.exit(0) when their main window closes, then the User could start the first app, start the second window within the first app's process. The user finishes what he is doing in the second app and closes the window. This calls System.exit(0), which also then closes the first window! If this is the case, calling the Runtime.exec() methods is better -- just make sure that you capture the output (if there is any) from the called program.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Launching an app within in app?