• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Launching an app within in app?

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 523
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic