I have two programs inside one of my eclipse project, one is the logic of the program, and another is the GUI. Both have their own main methods, and each of them execute as expected. Now, what I want to achieve is to run one program from another, i.e., when I press the button (from the GUI program), it should run the other program. How can I achieve this?
Asked
Active
Viewed 81 times
1
-
Are you new to java? – Apurva Mar 11 '15 at 03:45
-
2Don't do that. Use multithreading to work with GUI. – Everv0id Mar 11 '15 at 03:45
-
1Just like you did when you started them separately. Create an instance and call the methods (probably the `main` in this case). Having said that, it would be better to define methods that the GUI can call in order to interact with the logic... – MadProgrammer Mar 11 '15 at 03:46
-
@Everv0id Just beware, Swing and JavaFX are not thread safe... – MadProgrammer Mar 11 '15 at 03:46
-
Sounds like you need to stick to a proper design pattern if this is your issue. – Tdorno Mar 11 '15 at 03:47
-
you can get an [idea but it bad you should use multithread or oops concepts](http://stackoverflow.com/a/4843033/2749470) – Bhargav Modi Mar 11 '15 at 07:33
2 Answers
0
Keep business logic and program execution separately. Have your logic in separate methods as services. From your GUI directly call the service methods, not the main method.

Don Srinath
- 1,565
- 1
- 21
- 32
0
You should use Runtime class and use its execute method to run another java class which contains main() method.But note that you are creating two JVM instances by doing this !

Ravi Jiyani
- 919
- 1
- 10
- 26
-
@Don : Agree with your point, but thats what he is asking for.Yes Its actually bad design, but though if he has such requirement he can do. – Ravi Jiyani Mar 11 '15 at 03:56