Loading...
Logo
Processing Forum
Hello,

I am seeing different behavior when running from the Processing IDE vs running the exported application.  Specifically, for the 'X' button in the upper right corner that closes the program.  I have defined the exit() method so it will only call super.exit() if certain conditions are met.  It works fine in the IDE, but my exit() method does not even seem to be called when ran as the application.

I imagine it is a fundamental difference between the IDE and application environment, still looking for the truth.  

A little more background.  I want to write some information to a file.  If nothing has changed since the last save, then simply exit.  Otherwise, either refuse to quit until a save has been done or save automatically before exiting.  Thought I had it done, until I exported the application... :(

Any ideas?

Regards...bbc

Replies(3)

I tested it out and yielded the same results.
I always thought that it was a good solution...

With some research (looking at the Processing PApplet Reference and Source):

The source for exiting is... interesting...
It appears that when exit() is called, it then calls exit2() which simply calls System.exit(0), or hard quitting the application... overriding it should work.

My guess is that the operating system bypasses the function and calls System.exit(0)... not that that's anything different from what we thought before...

Looking into stopping it from being closed by the user:

Basically, PApplet uses a Frame rather than a JFrame, so you don't get access to functions such as:

Copy code
  1. frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

Perhaps you could embed the sketch in JFrame...

I would like to see this problem solved, but I don't have time for more research right now.
Quite frankly, the best solution would be on done in the Processing source...
Thanks for the confirmation.  I'll reply if I get something working... 
There was a long thread about the respective merits of exit(), dispose() and some other similar functions.
The problem is that it is difficult to predict the behavior of the system: it can warn before closing the application, or can be so brutal the program can do nothing. In the PDE, the IDE is the system, so it can control the process. In a browser or as an application, it is harder to control.