| Author |
message from one object to another
|
robert weninger
Greenhorn
Joined: Sep 29, 2004
Posts: 1
|
|
Hello, I am working on an IRC client have come to the following stumbling block. This is as much a project in learning how to program in java as it is to accomplish the task of writing an IRC client. I have 3 classes as follows: A - Handles connection with IRC server, sends and receives messages from server B - GUI, displays IRC messages and contains textbox for user input C - Main class, instantiates classes A and B. What I want to do is send a string from object A to object B, using using object C as an intermediary. Currently I have this implemented by using a loop to constantly check if the status of the incomming message string in class A (the IRC server communicator) has changes. This results in 100% CPU usage and is probably not the right way to go about this. My current thinking is that i need to pass a reference of object B into object A as a parameter ?
|
 |
Nick George
Ranch Hand
Joined: Apr 04, 2004
Posts: 815
|
|
|
sounds like a plan
|
I've heard it takes forever to grow a woman from the ground
|
 |
Jeff Bosch
Ranch Hand
Joined: Jul 30, 2003
Posts: 804
|
|
You could use threads. That would solve your cpu usage problem and could also solve your messaging problem as threads can communicate with each other. See PipedReader, PipedWriter, PipedInputStream, PipedOutputStream. [ September 29, 2004: Message edited by: Jeff Bosch ]
|
Give a man a fish, he'll eat for one day. <br />Teach a man to fish, he'll drink all your beer.<br /> <br />Cheers,<br /> <br />Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
|
 |
Nick George
Ranch Hand
Joined: Apr 04, 2004
Posts: 815
|
|
|
I must advise against threads. Your problem will be much more simply solved with sending references to objects that need references.
|
 |
somkiat puisungnoen
Ranch Hand
Joined: Jul 04, 2003
Posts: 1312
|
|
Originally posted by robert weninger: Hello, I am working on an IRC client have come to the following stumbling block. This is as much a project in learning how to program in java as it is to accomplish the task of writing an IRC client. I have 3 classes as follows: A - Handles connection with IRC server, sends and receives messages from server B - GUI, displays IRC messages and contains textbox for user input C - Main class, instantiates classes A and B. What I want to do is send a string from object A to object B, using using object C as an intermediary. Currently I have this implemented by using a loop to constantly check if the status of the incomming message string in class A (the IRC server communicator) has changes. This results in 100% CPU usage and is probably not the right way to go about this. My current thinking is that i need to pass a reference of object B into object A as a parameter ?
You should be used Thread in Class A and class A should observer object B every time. if object b change, object a MUST chenge too.
|
SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
|
 |
 |
|
|
subject: message from one object to another
|
|
|