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
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.
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...?
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL