-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConversation.java
More file actions
62 lines (54 loc) · 1.45 KB
/
Conversation.java
File metadata and controls
62 lines (54 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package Chat;
import java.util.Observable;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
* The conversation for the Chat program
*
* @author joar
*/
public class Conversation extends Observable {
private StringBuilder conversation;
/**
* Creates a new conversation
*/
public Conversation() {
conversation = new StringBuilder();
}
/**
* gets the HTML code of the conversation
*
* @return
*/
public String getHTML() {
return conversation.toString();
}
/**
* Adds a new message to the conversation
*
* @param message the message
* @param name name of sender
* @param color color of font
*/
public synchronized void addMessage(String message, String name, String color) {
conversation.append("<p><font color=").append(color).append(">")
.append("<b>").append(name).append(": ").append("</b>")
.append(message).append("</font>").append("</p>");
notifyObservers();
}
@Override
public void notifyObservers() {
setChanged();
super.notifyObservers();
}
/**
* Adds som information to the conversation
*
* @param info the info being added
*/
public void addInfo(String info) {
conversation.append("<p>")
.append("<b>").append(info).append("</b>").append("</p>");
notifyObservers();
}
}