• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Restarting Java Application  RSS feed

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have  a simple request. I just want to know how to restart an application from start using jave code.

Thanks for helping in advance.

 
Anthony Johnson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple button, and all I want to do with it is to restart the application.
 
Marshal
Posts: 60142
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Anthony Johnson wrote:I have  a simple request. . . .

I don't think you do. I think it requires a lot of explanation of what you mean by restart before we can help.

Don't use System.exit. You are supposed to be in a multi‑threaded environment when you are doing any Swing coding, and you can do serious harm with System.exit. Apart from the fact that System.exit makes it impossible to restart anything.
 
Anthony Johnson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok well in that case, how do I make it rerun the program in another window.
 
Campbell Ritchie
Marshal
Posts: 60142
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know. If you put anything in a loop, you are liable to have an endless loop running in the EDT and your performance will be very slow. You can't try anything asynchronous because Swing isn&apost thread‑safe. The nearest I can think of is to add a window listener: in the window closed method put a call to set up the GUI again. You would then end up with a recursive call of the set up GUI method. Or something like that.

It strikes me as strange that you would want to close a GUI window and then start the GUI again. Why?
 
Bartender
Posts: 3320
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Anthony Johnson wrote:Ok well in that case, how do I make it rerun the program in another window.


Do you mean you want to close the application and restart as a new instance?
 
Sheriff
Posts: 23713
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You keep saying "the application" and "the program" as if we should know what that means. It's easy to jump to the conclusion that "the application" means that code which you've posted there, but I suspect that's a wrong guess. So I would suggest you step back and provide a more complete description of what you're talking about.
 
Bartender
Posts: 620
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, you should be creating and displaying the frame from the Event thread, not the main thread.

Second, just eliminate the System.exit() call. Then every time you click on the button, the actionPerfomed() method will be executed.

Third, you will need some way to eventually exit the program, such as adding another "Exit" button and adding an event handler to that button, and that nahdler's actionPerformed() method should call  a method that will exit the application.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Fred Kleinschmidt
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!