Jump to content

JAVA - How to restart application

- - - - -

  • Please log in to reply
3 replies to this topic

#1
Serialcek

Serialcek

    Learning Programmer

  • Members
  • PipPipPip
  • 72 posts
Hi everyone :)

So what I want to do. I have a GUI application-simple game.
In this game I have a button Restart and when a user click it I would like that the application restart itself and start from the begining.

I tried something like this:


when button restart is pressed {  //pseudocode

try {

   Runtime.getRuntime().exec("java -jar application.jar");

   System.exit(0);

} catch (IOException e) {

}

}


This works 50%. What it does. It kills the precedent application and start the same again. But the first problem is that it takes samething like 1-2 seconds to do that. And in this time you can see on the desktop how the application dissaper and reaper.
I would to do that without dissapearint.. just restart the game.
And secondly it works only the first time.. if I want to restart it the second time it just close/exit itself.

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Create a new object of the Gui, and dispose the current?

#3
mariob316

mariob316

    Newbie

  • Members
  • Pip
  • 8 posts
ActionEvent {  //pseudocode

Classname.this.dispose();

new Classname();

}


#4
Serialcek

Serialcek

    Learning Programmer

  • Members
  • PipPipPip
  • 72 posts
Yes it works :)
Thx a lot guys




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users