01: package demo.chatter;
02:
03: import java.util.Random;
04:
05: public class User implements ChatListener {
06: private String name;
07: private String nodeId;
08: private transient ChatterDisplay display;
09:
10: public User(String nodeId, ChatterDisplay display) {
11: this .name = generateChatname();
12: this .nodeId = nodeId;
13: this .display = display;
14: }
15:
16: public String getName() {
17: return name;
18: }
19:
20: public String getNodeId() {
21: return nodeId;
22: }
23:
24: private String generateChatname() {
25: Random r = new Random();
26:
27: String[] cool = { "Miles", "Ella", "Nina", "Duke", "Charlie",
28: "Billie", "Louis", "Fats", "Thelonious", "Dizzy",
29: "Davis", "Fitzgerald", "Simone", "Ellington", "Parker",
30: "Holiday", "Armstrong", "Waller", "Monk", "Gillespie" };
31: return cool[r.nextInt(10)] + cool[r.nextInt(10) + 10];
32: }
33:
34: public String toString() {
35: return name + ", " + nodeId;
36: }
37:
38: public void newMessage(Message message) {
39: display.updateMessage(message.getUser().getName(), message
40: .getMessage(), this .equals(message.getUser()));
41: }
42:
43: public void newUser(String username) {
44: display.handleNewUser(username);
45: }
46: }
|