I developed one swing application but each time you run application new window is opened.
I want that if one window is already opened other not allow to open.
I developed one swing application but each time you run application new window is
Share
Here is an example of a Java Single Application Instance:
See also: A shorter example that does not notify the running instance.
The application tries to open a Socket on a specific port. In case another instance of your application is already running, opening the Socket fails.
This should already be sufficient for you, so you would not have to use the part of the code used to register new applications to the first one started.
Using a Socket has one great advantage compared to writing some sort of flag to the filesystem/registry/whatever:
It is removed even if your application crashes.