Srikanth
Srikanth

Reputation: 1930

How to execute MainApp.java program using Swings?

I have a problem in executing program when i click on Jbutton named GetSummary. I want the MainApp.java file to be executed when i click on the button names GetSumamry. Can someone please tell me what code should i write in actionPerformed function to run this program ??

Thanks in advance.

Upvotes: 1

Views: 299

Answers (2)

pajton
pajton

Reputation: 16246

You need to compile MainApp.javafirst. Then:

String[] cmd = {"java", "MainApp"};
Process p = Runtime.getRuntime().exec(cmd);

if you want to wait for the process to finish:

p.waitFor();

Upvotes: 1

user unknown
user unknown

Reputation: 36269

Since a main-Method has the signature

public static void main (String [] args)

you call it like every other static method:

String [] dummy = new String [0] ();

if you don't have arguments, an empty array,

MainApp.main (dummy);

returns void, so no assignment, and called by the class, not with a reference (new MainApp.main).

Upvotes: 5

Related Questions