Consider the following module:
startBrowser[] := Module[{},
$browserstatus = True;
ReinstallJava[CommandLine -> DIRJAVA, ClassPath -> DIRBOTA];
BROWSER = JavaNew["org.nilostep.botautil.BrowserFacade"];
];
and
stopBrowser[] := Module[{},
$browserstatus = False;
BROWSER@quitDriver[];
UninstallJava[];
BROWSER = Null;
];
and
controlPanel[]:=Manipulate[
If[$browserstatus, color1 = Green, color1 = Red, color1 = Gray];
Grid[{
{"Browser ", Graphics[{color1, Disk[]}, ImageSize -> 20]},
{"Hive ", Graphics[{color2, Disk[]}, ImageSize -> 20]
}}],
Button["Start Browser", startBrowser[];],
Button["Stop Browser", stopBrowser[];],
ControlPlacement -> Bottom,
Initialization :> {color1 = Gray, color2 = Gray}
]
Now, consider the following scenario:
controlPanel[]
the manipulate panel becomes, as expected, visual. Without clicking the buttons the browser is started and stopped as follows:
startBrowser[]
as a result the image in the panel changes from red to green and a Java- and browser instance can be seen in the Task Manager.
stopBrowser[]
as a result the image in the panel changes from green to red, the browser instance is killed after which the Java session is terminated.
Now, my question.
I expected that the same would happen when I click the buttons in the Manipulate program.
But when I click on the "Start Browser" button, a message appears with the text "One or more dynamic objects are taking excessively long, etc...". When I click "Continue Waiting" the button turns green and the Browser can be seen in Task Manager.
Then when I click the "Stop Browser" button, Java is uninstalled, but executing the quitDriver[] method on the BROWSER object failed.
I don't quite understand this behavior. How can I execute the start- and stop modules by buttons on the Manipulate panel?
Why do modules work when executed from a cell but have side effects when run from a button click action on a manipulate panel?