Put method at the closure of the frame/end of the program

Hello, was wondering how could i make something that when the user end the program a little bit of code would execute. If something like a error was to occur or the user simply close the window for the application (and so end the application) how could i force the program to make anything?

Can i use a setActionOnClose or something like that?


Okay but how do i use it? i try to modefy it and @Override in my main but it do not seem to work. So what should i do? creat a interface from the appstate and then modefy it? Or… what? xD


1 Like

Alright thanks, it work. So if i make something like this
public class AppsSta extends AbstractAppState

 public void cleanup() 
      System.out.println("J'aime les chèvres") ;


Then i go and make this
public static void main(String[] args) {
Main app = new Main();
app.stateManager.attach(new AppsSta()) ;



I mean it work but kinda fell wierd xD

Well, given the limited amount of information you provided on what you want to do, I had to limit the amount of information I gave you back.

Not knowing about app states puts you in the very beginner basics of JME usage… so it’s worth learning.

I mean am okay whit the learning and everything but does what i just did work? Cause it look wierd to add a whole new app state does it consume ressource?

If you need info well to put it simple i want my app to send a packet to the server after the client disconnect or get disconnect. I already got the packet, the server and everything but i still need the app the send it. I mean if the out.println work i should be able to make the paket work just fine, but as i said, this way to do things fell wierd to me.

See… that’s a larger question. You would probably want an app state to manage your whole network connection. And in that case it could send the packet on cleanup. Though, really, there is no way to guarantee that the packet gets there before the process dies.

If you are using spider monkey for your networking then you don’t even need to do that, really. And if you aren’t, well… networking is hard enough. You definitely shouldn’t be doing it from scratch. (At your skill level you should consider not doing networking at all until you’ve made at least one single player game. Networking makes things 1000x harder.)

Well i am building a turn based game, so multi player should be quite easy to handle, at lest for the combat state. For what is of building a game well i am crasy enouf to work on it a lot, and realy so far so good.

I don’t realy see what is so hard whit networking to be honest, i already build a pretty good connection page from scratch and it work very well. I also created a method so that my client whould poke the server to see if he is or not online, The whole system of packet once you underthand it is realy easy to handle. That is of corse if am not doing any huge mistake whiout knowing it x)

But ya, il check out spider monkey a bit more but realy from what i can see this is just some already build packet. Usefull one i must agree but i already got a couple. Then again from what you seem to say, it also work on the appState part and this could help the optimisation part maybie? I realy don’t know, this projet is both just a pratice and somehow something id like to be able to put on the market one day… like in 3 year or so x)