HELP! -- getting a JApplet to get notified when a JFrame is closed...


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: HELP! -- getting a JApplet to get notified when a JFrame is closed...

  1. #1
    Join Date
    Jun 2004
    Posts
    2

    HELP! -- getting a JApplet to get notified when a JFrame is closed...

    Hi, I'm programming an application for my company which requires that my JApplet create an instance of a JFrame. I have both the applet and frame completed, but I can't figure out how to get the JApplet to become notifed when the instance of JFrame is closed by the user...

    I tried putting a listener on the JFrame, but I couldn't figure out how to look for when the JFrame was closed by the user.
    Another method I tried was setting the focus on the JFrame to freeze operation of the Applet until the Frame lost focus, but I couldn't get that to work..

    Any Suggestions and help would be greatly appreciated.


    here is my code which creates the JFrame in the applet...
    (QuadCharts is a JFrame)

    QuadCharts quadFrm = new QuadCharts(slideName, chartNames);
    quadFrm.show();

    ideally, after I call show, i wan't the JApplet to stop and waith for the JFrame to close, in order to perform a set of operations when the Frame has completed its tasks.


    Thanks!
    nullkill

  2. #2
    Join Date
    Aug 2003
    Posts
    313
    Hey, you might try using a JDialog instead. It looks very similar to a frame except that it keeps focus until it is closed if model is set to true. Hope this helps.
    ~evlich

  3. #3
    Join Date
    Feb 2004
    Posts
    808
    you could make your applet "implements WindowListener", then make it the windowlistener for the frame jframe.addWindowListener(this)
    then, when the frame is closed, the applet will receive an event notification that the frame is being closed.
    the applet must implement the public void windowClosing(WindoEvent e) method
    from e the source window (i.e. the frame) can be obtained using e.getWindow().

    note that it will then be up to the applet to hide or dispose of the window
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

  4. #4
    Join Date
    Jun 2004
    Posts
    2
    I can't use the JDialog, b/c my design requires a JFrame, and I dont want to modify the code to have the Frame in the Dialog... Good suggestion though.

    As for the Window Listener, That will work for me. Thanks for you help!
    -NulLKilL

  5. #5
    Join Date
    Oct 2002
    Posts
    12
    I'm not sure where this'd go, as I'm only doing this hypothetically....

    You could overwrite the setVisible method to something like:
    Code:
    public void setVisible(boolean vis){
      if(!vis) appyThread.start();
      else appyThread.stop();
      super.setVisible(vis);
    }
    where appyThread is the thread that runs the appet and is passed as a parameter in the constructor of the QuadCharts object.

    I have not tested it, but I do think this'd work.

  6. #6
    Join Date
    Feb 2004
    Posts
    808
    please do not advise people to use Thread.stop(), Thread.suspend() or Thread.destroy(). These methods have all be deprecated for good reasons of application stability.
    If your java compiler does not warn you that these methods have been deprecated, you should get a more recent version of Java (and welcome to the 21st century by the way..)
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

  7. #7
    Join Date
    Oct 2002
    Posts
    12
    merp... sorry... I'll know better next time

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center