File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes closing applet by clicking button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "closing applet by clicking button" Watch "closing applet by clicking button" New topic

closing applet by clicking button

srikanth narra

Joined: Jun 28, 2001
Posts: 6
I need to close an applet with click of a button.I tried with system.exit and dispose .Both of them to do this???
Srikanth narra
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
Again, an applet can't stand-alone, so it is not possible to close it. Are you mistaken an applet for an application? The closest solution I can think of is as follows:
Create an applet and embed that applet in an html page. Within that applet include a button. When this button is pressed have a window popup (still part of the original applet) and add whatever functionality you want in your "stand-alone" applet into that pop-up frame. Within this frame you can have a button, that when pressed disposes of the frame. That's the best I can offer.
Tina Parks
Ranch Hand

Joined: Jun 30, 2001
Posts: 35
I think it would be easier to include a button on the web page that pops up a window that contains the applet. In the popup window you can have a button that closes the window.
You can see an example on the Web at . Notice that the "Applet Help" button pops up a window containing some text and a "Close" button. The "Open Applet" button, on the other hand, pops up a window containing an applet. Installing a similar "Close" button on the applet window would be very easy.
Try it and see if this is the kind of functionality you are looking for.
Charlie Boss
Ranch Hand

Joined: May 22, 2001
Posts: 44
hi srikanth,
I used javascript to achieve this and its easier than it seems.
Here are the steps:
import netscape.javascript.*;
//in the actionlistener for the "close" button call destroy()
//in destroy after doing all your cleanup call
//the above code will call the javascript function shutDown which should be defined in the <head></head> of your html containing your applet tags.. hope this helps
oh yeah.. in your applet tags you must have this parameter..

[This message has been edited by Charlie Boss (edited July 06, 2001).]

Java Rawks
I agree. Here's the link:
subject: closing applet by clicking button
It's not a secret anymore!