11

When run the project second time, can the previous JFrame closed before open the new one ?

So I no need to close the JFrame when trying to run the project second time.

enter image description here

Is it possible to open only one JFrame?

John Joe
  • 12,412
  • 16
  • 70
  • 135
  • A JFrame instance starts via eclipse . But it is run in the underlying os. Eclipse don't have the control on it. – VNT Jun 03 '17 at 15:30
  • Is your point that you don't want to manually quit the previous execution of your code? – Dave Newton Jun 03 '17 at 16:28
  • 1
    https://stackoverflow.com/questions/7036108/prevent-launching-multiple-instances-of-a-java-application – hsirkar Jun 03 '17 at 16:49
  • You can terminate the application from eclipse or just exit the JFrame by setting it to exit on close. `setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);` – parabolah Jun 10 '17 at 01:58

5 Answers5

18

Eclipse has the possibility of terminating the launched program before starting the new one: It is called Terminate and Relaunch (see the Documentation).

You can bind this to any shortcut you like (Window -> Preferences -> General -> Keys).

Tobias Walter
  • 436
  • 2
  • 7
3

Apparently, eclipse offers some special options to get what you want.

For other people who might be using a different editor: it's possible, but you'd need some kind of communication between the processes.

What you can do is this, make a server application that runs independently and have it open before you start your regular application. When you run your regular application, connect to the server. This server now messages the other application that was running to close down.

If running a server application is too much trouble, you can run both the server and the client in the same application. When you start the application, check if the designated port is busy, if not, create a server. If it is busy, connect to the server and tell it to shut down. After that, open the server socket in the new application.

Thijs Steel
  • 1,190
  • 7
  • 16
3

Select the Terminate and Relaunch command [ Terminate and Relaunch ] to first terminate the selected debug target and secondly, relaunch it.

Once a launch is terminated it can be automatically removed from the Debug View. To change this setting use the Opens the Launching preference page Run/Debug > Launching preference page.

Vikas Suryawanshi
  • 522
  • 1
  • 5
  • 12
2

you may find relaunch-plugin for eclipse useful for your case.

Daniel Taub
  • 5,133
  • 7
  • 42
  • 72
0

I don't know about eclipse but i usually run two or more JFrame applications in (IntelliJ idea) belonging to different classes at a time. The previous one will not be closed. One more thing i would like to suggest you to use IntelliJ Idea from Jetbrains company as the UI,shortcuts and all other stuff are same as in Android Developer kit(studio) which is also sponsored and developed by Jetbrains!..

You can check the JFrame applications running simultaneously in this image.

Hope this answer is somewhat informative.......
!>...

jayanthsaikiran
  • 180
  • 1
  • 10