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

close button

Jade Davidson
Ranch Hand

Joined: Oct 12, 2001
Posts: 64
How do I program a button for closing down the applet? I always thought it was closed manually by the user clicking on the mouse, but I am supposed to write an applet that uses a "close" button to close down.
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Well there is more than one way to do this.
If you were going to use the X in the corner you would either create a class and extend WindowAdapter, or implement WindowListener.
However, since you need a button to do this, you need to create a class to implement something that Button listens to. One of the things that Button listens to is an ActionListener. (You can check this by looking in the API and checking what addXXXListener methods the component has).

Now you have to create a gui and on that qui you need to make a button. When you have your button, you need to create an instance of your listener, and then hook the two together.

Now all you need is to get this in an Applet or a Frame, and all should be good.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Jade Davidson
Ranch Hand

Joined: Oct 12, 2001
Posts: 64
Thank you.
I agree. Here's the link:
subject: close button
It's not a secret anymore!