Nikolay Kuznetsov
Nikolay Kuznetsov

Reputation: 9579

How to terminate applet gracefully?

My applet is supposed to take external parameters from html file which might be dynamically generated.

<param name="type1" value="value1">
<param name="type2" value="value2">

Those parameters has to be checked for validity in Applet.init()

String type1 = getParameter("type1");
String type2 = getParameter("type2");
if (type1 == null || type2 == null) ....

And they are wrong what should I do? Is it okay to call Applet.destroy() manually?

As I know stop and destroy are supposed to be called by browser, not applet itself.

Upvotes: 0

Views: 771

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168825

Applet.destroy() should only be called by the JVM.

The best strategy here is to redirect to a page that shows the parameters and what is wrong with them. To do that, use something like:

URL brokenParams = new URL(this.getDocumentBase(), 
    "badparams.html?type1=" + type1 + "&type2=" + type2);
this.getAppletContext().showDocument(brokenParams);

This will have the effect that:

  • The applet page will vanish, replaced by..
  • badparam.html which shows the params and describes the problem. Then..
  • When the JVM browser combo. decides it is the right time, the Applet.destroy() method will be called. (The 'right time' is typically 30-60 seconds later by my reckoning.)

Upvotes: 1

Related Questions