aspose file tools*
The moose likes Applets and the fly likes Avoid several launches of the same applet at the same time within the same page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Avoid several launches of the same applet at the same time within the same page" Watch "Avoid several launches of the same applet at the same time within the same page" New topic
Author

Avoid several launches of the same applet at the same time within the same page

Xeon Dev
Greenhorn

Joined: Feb 07, 2012
Posts: 2
Hello,
I have jsf/xhtml page in which there are several buttons which all launch the same applet but with different initial values.
The point is to avoid launching several instances of the applet at the same time. That means a user can not have several open applets if he clicks on some of those buttons.
If an applet is currently open, and the user clicks on another button to launch a new applet, he should get an error message that an instance of the applet is open and he can not open a new one. Once the currently open applet is closed, the user can launch a new one by clicking on another button.

For that I used a boolean in init method of the applet. When initializing the applet I set it to true and when submitting or closing the applet, I set this boolean to false within the stop() method which is called while submitting or closing.

The problem: if an applet is open, I click a new button... it do not launch a new applet as this boolean is true. Every things seem good.... but if I click on a button which is previously clicked (used to launch an instance of the applet and that applet is now closed)... it closes the currently loaded applet and load a new one with the initial values of the clicked button. I traced the code, and I saw that when I click a previously clicked button (used to launch an instance of the applet and that applet is now closed) it call first the stop method of the open applet and thus that boolean value becomes false and then it thus initialize a new applet. but when I click on a new button (never previously used to launch the applet), it do not call the stop method and thus a new one can not be initialized as the boolean is currently true.

I have no idea what to do...
Many thanks
Bye.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
http://stackoverflow.com/questions/9186097/avoid-several-load-of-an-applet-at-the-same-time-in-the-same-page
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Avoid several launches of the same applet at the same time within the same page