Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

close button

 
Jade Davidson
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jade Davidson
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic