Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

message from one object to another

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sounds like a plan
 
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I must advise against threads. Your problem will be much more simply solved with sending references to objects that need references.
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic