Accessing variables between classes?

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Accessing variables between classes?

Hybrid View

  1. #1
    Join Date
    Mar 2005

    Question Accessing variables between classes?


    I am currently building an instant messaging client server application and have hit a brick wall as far as I can see....I was wondering if someone could help?

    I have an initial class that takes user input via a textArea and a seperate class that gets fired off on the click of the submit button which handles all the socket stuff. Now I have all the communication working via command line but how can I get the variables (message) back to the initial class (gui) each time a message is sent between 2 user? The only way I know how to get variables between classes is via constructors....

    Should I merge the two classes or what?

    Thanks in anticipation

  2. #2
    Join Date
    Feb 2004
    Just write a method in the class that controls the text area that accepts the message string (and possible another string for the senders name), and this method will then write the message to the screen.

    The object that you sent over the network will need to have a method that can be called to get the message from it. This method will be called by the chat engine when it recieves a message object over the network, and then passed to the object that controls the textarea.

    Have a search for getter and setter methods on google, it will give you the basic idea.

  3. #3
    Join Date
    Aug 2004
    Dublin, Ireland
    Surely a simple approach to this would be to instantiate the text entry class and the networking class in your application's entry point/constructor. Then you can just reference either by name...?

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
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

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