Results 1 to 2 of 2
  1. #1
    tamayo is offline Member
    Join Date
    Jul 2007
    Rep Power

    Default how to access to an object from a thread

    Hi, I have to classes in my app
    the first: the public class that contains the main method and inside it I defined all my GUI, including the control txtData. From it the "client" Thread is called.

    the second: the "client" thread class that tries to do this:
    txtData.append("The client saids: "+i.readLine());

    So, the error I obtain is:
    Can't find the symbol: txtData.

    I think that this control, txtData, doesn´t exist inside of "client" thread class, so my question is:

    How can I have "access" to txtData and to do append to it from the "client" thread class?

    Thanks a lot for your help

  2. #2
    katie is offline Member
    Join Date
    Jul 2007
    Rep Power


    when you compile the thread you have to give it some reference to the class that has txtData, so that the thread can access to it through get method.

    From the class that calls the thread you can do that
    Java Code:
    MyThread myThread = new MyThread(txtData)
    and thread class has an attribute to save the reference to txtData

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2010, 02:12 AM
  2. data from the main/GUI thread to another runnin thread...
    By cornercuttin in forum Threads and Synchronization
    Replies: 2
    Last Post: 04-23-2008, 10:30 PM
  3. Replies: 0
    Last Post: 01-28-2008, 07:02 AM
  4. Replies: 1
    Last Post: 08-07-2007, 07:51 AM

Posting Permissions

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