Processing and stop() method



我想在退出处理草图时执行一些操作。我在论坛上发现,方法stop()是在应用程序退出之前调用的。我试过了,但在我看来,它从来没有被调用过。下面是一个最小(不起作用)的例子:

void setup()
{
 size(100, 100);
 println("start");
}
void draw()
{
  //nothing here
}
void stop()
{
  println("called stop()");
  super.stop();
}

退出应用程序时,通过IDE上的停止按钮或通过应用程序上的X按钮,我从未看到消息"called stop()"。我尝试了使用和不使用super.stop(),没有任何变化。感谢

处理2.2.1,在Linux上Debian Wheezy

stop()函数是PApplet扩展Applet的遗留函数。除非您作为小程序进行部署,否则将永远不会调用stop()函数。即使您是作为小程序部署的,stop()函数仍然不能保证被调用!PApplet API中的更多信息。

假设您使用的是Java模式,您可能会考虑添加关闭挂钩,或者只在框架中添加WindowListener。

除了Kevin的答案之外,您还可以重写exit()方法:

void setup(){
  println("start");
}
void draw(){}
void exit(){
  println("stop");//do your thing on exit here
  super.exit();//let processing carry with it's regular exit routine
}

最新更新