Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

help me understand a exam in 《Java Threads Third Edition》  RSS feed

 
xie yufei
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public interface CharacterSource {

public void addCharacterListener(CharacterListener cl);

public void removeCharacterListener(CharacterListener cl);

public void nextCharacter( );

}

public interface CharacterListener {

public void newCharacter(CharacterEvent ce);

}

public class CharacterEvent {

public CharacterSource source;

public int character;

public CharacterEvent(CharacterSource cs, int c) {

source = cs;

character = c;

}

}
Up three classes they use each other, how can I compile them?
 
Henry Wong
author
Sheriff
Posts: 22832
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would recommend going to the O'Reilly Website for the examples' source code. Many examples in the book are snippets for readability purposes.

The source code are arrange by chapter and example. And even include an Ant script to help compile them. There is also a small example in chapter one which discusses the compilation of the examples.

Henry
 
xie yufei
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry,Thanks for your kindness.The problem I have resolved ,but I can't understand the program , what are the standard Java pattern of event listeners ,and can you recmend somethings to read.
Thanks again for your help!
 
Henry Wong
author
Sheriff
Posts: 22832
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by xie yufei:
Henry,Thanks for your kindness.The problem I have resolved ,but I can't understand the program , what are the standard Java pattern of event listeners ,and can you recmend somethings to read.
Thanks again for your help!


That pattern is used extensively in Java -- most notably in Swing / AWT programming. I believe the design pattern book calls it the observer pattern -- but I am not sure anymore.

IMHO, I would not worry about it too much in chapter one. It may actually be a bit overkill for the chapter one examples. The reason we are doing it that way is because we will be creating separate threads for the parts of the application later. It is more of a building block example for the later chapters.

Henry
 
xie yufei
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh,Thanks very much,Henry!
[ December 29, 2005: Message edited by: xie yufei ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!