Hi,
I have the following buttons:
- Stop
- exit
- Restart
The button "stop" uses the finish() method of the engine. I don't use stop() because I don't want to return
to the simulation main page. Is that correct?
The button "exit" ought to close the window. How can this be achieved? An alternative would be to return to
the simulation main page.
The button "restart" shall reset the simulation and restart. I didn't find something in the help about a
possible restart.
thanks for your help
greetings
Sergey Suslov — 13.08.07
Hi,
If I understood you in the right way, you are trying to create custom buttons in the "Main" page to control
the simulation. My suggestions are:
1. "stop"
Just call "getEngine().stop();" to pause the model, and "getEngine().run();" to run it.
2. "exit"
Use these a couple of code lines to switch the screen to the simulation main page.
getEngine().finish();
getEngine().getPresentation().setPresentable( getExperiment() );
3. "restart()"
Use the code bellow
getEngine().finish();
((Simulation)getExperiment()).button.action();
I hope this helps.
Best regards,
Sergey Suslov
Sergey Suslov — 13.08.07
P.S. Please use "getEngine.pause()" in the (1) instead of "stop()".
M.Fischer — 14.08.07
Thanks for your answer.
1. I have a pause and a stop button. So I think getEngine().stop() is correct for the stop button but there seems to be
a problem. getEngine().stop() doesn't work...I click on the button, call the stop() method and after that the whole
simulation is stuck. Any ideas?
2. Works
3. the simulation doesn't really restart, it's still in the same state than before. The button the main page uses the
following code:
run();
pause();
I use pause() because I dont't want that the simulation starts immediately. Restart should also reset the simulation,
like a complete new run...
Victor Gleim — 15.08.07
Hello!
1. What do you mean when say "stuck"?
3. Try to use the following code:
getExperiment().stop();
getExperiment().run();
getEngine().getPresentation().setPresentable( getEngine().getRoot() );
Best wishes,
Victor
M.Fischer — 05.09.07
Hi,
I just found the problem about the "stop" button. When the user clicks on the "stop" button there
shows up a confirmation dialog. If I leave out this dialog it works, if not it doesn't work. The code of the
"stop" button:
int selection = 0;
selection = javax.swing.JOptionPane.showConfirmDialog(null, "end simulation?");
if (selection == javax.swing.JOptionPane.YES_OPTION) {
System.out.println("DEBUG: YES_OPTION");
getEngine().finish();
}
Victor Gleim — 05.09.07
Hello!
Try to use the stop method instead of the finish.
Best wishes,
Victor
M.Fischer — 05.09.07
The stop method causes the same result. It works only if I leave out the dialog. The debug message works, but if I place
another message after getEngine().stop() the second message doesn't appear. Also there is no functionality of any
element of the simulation...
Victor Gleim — 05.09.07
Hello!
The following code must work. It can scare, but this is the correct way to do what you want.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
getEngine().pause();
int selection = javax.swing.JOptionPane.showConfirmDialog(null, "end simulation?");
if (selection == javax.swing.JOptionPane.YES_OPTION) {
System.out.println("DEBUG: YES_OPTION");
getEngine().stop();
} else {
getEngine().run();
}
}
});
By the way, I have added some functionality to the code in order to pause the simulation when the dialog appears.
Best wishes,
Victor
Igor Mesterovic — 23.04.08
Hello.
Im working on something similar like this. I have need for restart simulation after fulling one of queues.
So after this function
if(queue1.size()==queue1.capacity){
queue1.removeFirst();
getEngine().pause();
int selection = javax.swing.JOptionPane.showConfirmDialog(null, "Kasa1 je prepunjena. Pocni simulaciju iz
pocetka?");
if (selection == javax.swing.JOptionPane.YES_OPTION) {
System.out.println("DEBUG: YES_OPTION");
getEngine().run();
getExperiment().stop();
getExperiment().reset();
getExperiment().run();
getEngine().getPresentation().setPresentable( getEngine().getRoot() );
} else {
getEngine().finish();
}
}
Restarting is done, but with errors: (note that after first time there is no Error Dialog, second, third... have it):
----- CONSOLE:
DEBUG: YES_OPTION
Exception in thread "AnyLogic model execution thread" java.lang.NullPointerException
at com.xj.anylogic.engine.Engine.h(Unknown Source)
at com.xj.anylogic.engine.Engine.a(Unknown Source)
at com.xj.anylogic.engine.Engine$a.run(Unknown Source)
Exception during stopping the engine:
java.lang.RuntimeException: INTERNAL ERROR(S):
Engine still has 1 active predicates
java.lang.RuntimeException: INTERNAL ERROR(S):
Engine still has 1 active predicates
at com.xj.anylogic.engine.Engine.stop(Unknown Source)
at com.xj.anylogic.engine.ExperimentSimulation.stop(Unknown Source)
at com.xj.anylogic.engine.presentation.Presentation.m(Unknown Source)
at com.xj.anylogic.engine.presentation.Presentation.c(Unknown Source)
at com.xj.anylogic.engine.presentation.Presentation$c$a.run(Unknown Source)
-----
also one more note, getEngine().stop(); errors with:
java.lang.RuntimeException: stop() can not be called from the model execution thread, use finish() or pause()
Any ideas?
Thanks
Pavel — 06.05.08
I recommend you to send your model to the XJ Support Team (http://www.xjtek.com/support/ask_question/). They will be
able to test it and try to find out the probable cause of such behavior of your model.