aspose file tools
The moose likes Applets and the fly likes JApplet & WindowListener Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Applets
Reply Bookmark "JApplet & WindowListener" Watch "JApplet & WindowListener" New topic
Author

JApplet & WindowListener

Matthew Orral
Greenhorn

Joined: Jul 27, 2003
Posts: 11
I need to call a method only after the JApplet is closed, i was thinking about windowlisteners but in the JApplet init method, adding ((JFrame) this.getParent()).addWindowListener(this) didn't work (compiles well,but raises exceptions) (the JApplet implements windowListener methods, for the moment all blanks).
How can I add a window listener to a JApplet (not a standalone app with a JFrame, but a simple applet for the web (whitout main))?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24054
    
  13

The code throws an exception because the parent of a JApplet won't usually be a JFrame (it'll pretty much never be -- it might be the content pane of a JFrame, but not the JFrame itself.) But most of the time, it won't be a Java window at all -- it's the browser window.
You don't want to use a Window listener. All you need to do is to override either the stop() method of JApplet (which is called when the user browses away from the page the applet it on; start() may be called again if the user browses back) or destroy() (which should be called at the very end of the applet's life.)


[Jess in Action][AskingGoodQuestions]
 
jQuery in Action, 2nd edition
 
subject: JApplet & WindowListener
 
Similar Threads
Catching the window cross button in JFrame
Jframe and JApplet
jtable editing
What's the difference between a window being deactivated and losing focus?
Image in JFrame which opens from a JApplet