How to exit and run again the Application

Hi allI want to do a restart button. that mean when I click on this button his job is to close the application and run it again.thanks for your help
[169 byte] By [Programersa] at [2007-11-26 19:09:35]
# 1
Start the application from a start script. The script should restart the application if it terminated. You can't restart from within the VM.Kaj
kajbja at 2007-7-9 21:04:36 > top of Java-index,Java Essentials,Java Programming...
# 2
but what is the event that occur when I close dhe application.
Programersa at 2007-7-9 21:04:36 > top of Java-index,Java Essentials,Java Programming...
# 3
> but what is the event that occur when I close dhe> application.None? But your script can get the exit code of the application.Kaj
kajbja at 2007-7-9 21:04:36 > top of Java-index,Java Essentials,Java Programming...
# 4
for example I used something like this:MultiPPC1.main(args);to start again but I didn't close the previous application
Programersa at 2007-7-9 21:04:36 > top of Java-index,Java Essentials,Java Programming...
# 5

> for example I used something like this:

> MultiPPC1.main(args);

>

> to start again but I didn't close the previous

> application

Read what I said. You need to terminate the application, by e.g. executing System.exit(1), and then restart from a script.

Kaj

kajbja at 2007-7-9 21:04:36 > top of Java-index,Java Essentials,Java Programming...
# 6

OK!

have a look to my code:

if( e.getActionCommand().equals( "exit" ) )

System.exit( 0 );

else if( e.getActionCommand().equals( "restart" ) )

{

System.exit(1);

String[] args = new String[0];

try {

MultiPPC1.main(args);

} catch (IOException e1) {

e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.

}

}

Programersa at 2007-7-9 21:04:36 > top of Java-index,Java Essentials,Java Programming...
# 7
Nothing after System.exit(1) will be executed. Do you know what a start script is?
kajbja at 2007-7-9 21:04:36 > top of Java-index,Java Essentials,Java Programming...
# 8
Actualy I don't know. but you understand that what I want. can you help me?
Programersa at 2007-7-9 21:04:36 > top of Java-index,Java Essentials,Java Programming...
# 9

> Actualy I don't know. but you understand that what I

> want.

Yes

> can you help me?

A start script is a file that launches your application, e.g. a bat-file, a cmd-file or a linux/unix-script. You need to write a script with a loop which checks the exit code and executes the app again if needed. That is not Java releated and platform dependent, so please google.

Kaj

kajbja at 2007-7-9 21:04:36 > top of Java-index,Java Essentials,Java Programming...
# 10
aha yesjust now I understod you. because I thought that was related with java! ok! thanks for your help and see you again. bye
Programersa at 2007-7-9 21:04:36 > top of Java-index,Java Essentials,Java Programming...
# 11

A start script is overkill, especially if this is just a user application that might just be run once and quit, not to mention that platform dependence of it. If that's what you're considering, I would recommend doing something likeRunTime.getRuntime().exec("java My_Program");

System.exit(1);

instead, which would start a whole new JVM running your program, and then kill the original. Not exactly pretty or efficient, but it would restart it.

Shadowicsa at 2007-7-9 21:04:36 > top of Java-index,Java Essentials,Java Programming...
# 12
> likeRunTime.getRuntime().exec("java> My_Program");> System.exit(1);>That might or might not work. The process that you execute will halt if the output streams (stdout and stderr) get
kajbja at 2007-7-9 21:04:36 > top of Java-index,Java Essentials,Java Programming...
# 13
but the method getRunTime() doesn't work it give error.
Programersa at 2007-7-9 21:04:36 > top of Java-index,Java Essentials,Java Programming...
# 14
sorry sorryI used RunTime instad Runtime.thanks for your help
Programersa at 2007-7-9 21:04:36 > top of Java-index,Java Essentials,Java Programming...