Results 1 to 2 of 2
  1. #1
    frejon26 is offline Member
    Join Date
    Jan 2008
    Rep Power

    Default Communicating between Dialogs and Frames

    I apologize if this is a rather stupid question, but I am tired... I understand that Swing is not thread safe and requires you to create threads for any heavy lifting to be done in the background, or use the SwingWorker utility class (which will create threads for you with the doInBackground method etc)...

    I'll just get to my question, I have a JFrame class that contains a SolidWorksLoader instance that I have written as well as a MyFileChooser instance that extends from JFileChooser (from the Java core language). The MyFileChooser class looks like this...
    Java Code:
    import javax.swing.*;
    public class MyFileChooser extends JFileChooser implements Runnable {
      private Component parent;
      public MyFileChooser(Component p){ parent = p; }
      public void run(){
        //all filechooser setup is done here...
          case JFileChooser.APPROVE_OPTION :
              ?? is there an easy way to communicate back to the parent's thread
                 the file that was selected? and then let this thread end... ??
    I am instantiating this class like so...
    Java Code:
    //JFrame class
    MyFileChooser choose = new JFileChooser(this);
    Say I have a File object in my JFrame class that I want to set From the MyFileChooser ..., aside from directly setting it using a setter method which would keep the FileChooser thread in business... is there any way to getthe File to the Parent's (JFrame's) thread of execution and let the FileChooser's thread die? Am I thinking about this wrong?
    Last edited by frejon26; 05-23-2010 at 05:34 AM. Reason: forgot some syntax

  2. #2
    frejon26 is offline Member
    Join Date
    Jan 2008
    Rep Power


    hmm last thought before I crash into bed... I think i get it... After the File is set from the dialog thread it's thread of execution then ends, and the JFrame (the gui thread) continues to listen for user input, only now the data has been updated, so the program can continue (so you do not have to get the data back to the parent's thread). I think all I would need to do is make the shared resource, (The File) volatile, so that separate threads do not create their own instance of it.... I think I get it, any comments could definitely be useful though.

    Last edited by frejon26; 05-23-2010 at 05:52 AM.

Similar Threads

  1. Replies: 0
    Last Post: 04-27-2010, 12:15 PM
  2. How do I get all dialogs?
    By zenteo in forum AWT / Swing
    Replies: 6
    Last Post: 03-08-2010, 11:01 PM
  3. Passing data between dialogs
    By Wintery in forum New To Java
    Replies: 7
    Last Post: 01-02-2009, 06:35 AM
  4. Java Server & C# client communicating through sockets
    By yukijocelyn in forum Networking
    Replies: 0
    Last Post: 09-05-2008, 10:05 PM
  5. Communicating with JSP and popup
    By nilz in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-20-2007, 05:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts