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

Jframe and JApplet

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
ok, say I have a chatclient running in a jframe to display it. And then I put that same client in a web page as an applet.

when i close the page the applet is on, is that equivilant to pressing the close 'X' on the jframe?

Thanks A Lot,

Justin Fox

You down with OOP? Yeah you know me!
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
and if so, if i close the JFrame/JApplet will that close the socket that is open in that chatclient?

or do i need to put a windowlistener in to check to see if its open?
or something along those lines.


Justin Fox
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

When you push the 'X' of a JFrame, this generates a WindowEvent, which is sent to any WindowListeners you have attached to the JFrame (and the windowClosing/windowClosed method of the listener is called).

Applets/JApplets have lifecycle events in the Applet class to handle things like navigating away from the page, the applet being destroyed, etc. applet.destroy() is probably analogous to pressing the 'X' to close an application - however, it's probably better to create a socket in start() and release/destroy it in stop() - this means that the applet won't hang onto the socket while it's not 'active' (i.e. the use has navigated away from the page the applet is on).

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: Jframe and JApplet
It's not a secret anymore!