Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

JApplet & WindowListener

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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))?
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Nothing? Or something? Like this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic