Is there a way to get only one program? [JAVA Mode Program]

Is there a way to get only one program?

When you click an exe file N times, N programs are turned on.
So, is there a way to turn on just one program with N clicks of an exe file?

How can I run only one program with N clicks?

Please help me. ~~

1 Like

From the screenshot, I can see you are using Windows. One idea is that you run the tasklist command from Processing and search for current running sketches. If there is one, then you kill the current sketch.

Another approach is that you check for an environmental variable. If it does not exist, launch the sketch and set it. Otherwise, do not lunch the sketch. In addition, you need to override the exit() method so you unset the variable when the current program is terminated by the user.

these are all concepts. You need to work in the fine details of the implementation. There could be better ways to do it. You should explore StackOverflow for alternative generic solutions.




thank you for your reply.

Let’s improve by the above method.
thank you.


That’s a good way.
Thank you.

1 Like

This also depends exactly what trying to open the program again is meant to do? Quite a few programs will open a local server socket, which can only be done by the first. Subsequent attempts will connect and pass data to that first instance. This is how PDE itself handles this I think - see

Okay, I see. Thank you.

How is this done please?

Alternatively you can just write yes or no in a file amirunning.txt using saveStrings and loadStrings. When finding yes in setup it exits

@Chrisir These posts [1, 2] are in my records. I also have this snippet. They need to be tested against each renderer separately. For JAVA2D, it works when hiting the x button on the window, Alt+F4 (Windows), pressing ESC or hitting any key. For P2D the Alt+F4 does not work.


void setup(){

void draw(){background(0);ellipse(mouseX,mouseY,50,70);}

void keyPressed(){
 if(key==' ') exit(); 

private void prepareExitHandler () {

  Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

    public void run () {

      System.out.println("SHUTDOWN HOOK");

      // application exit code here

Thanks a lot!
Really appreciate it.

1 Like