KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > examples > chat > Message


1
2 package org.objectweb.proactive.examples.chat;
3
4 import java.io.Serializable JavaDoc;
5
6 /**
7  * This Class defines the Message (exchanged by the users)
8  *
9  * @author Laurent Baduel
10  */

11 public class Message implements Serializable JavaDoc {
12
13     /** The message */
14     private String JavaDoc s;
15     
16     /**
17      * Constructor : builds a message from a String
18      * @param source - the string
19      */

20     public Message(String JavaDoc source) {
21         s = source;
22         if (!(s.endsWith("\n")))
23             s += "\n";
24     }
25
26     /**
27      * Constructor : builds a message from a String. The message will contain the name of the user and the date of writting.
28      * @param author
29      * @param source
30      */

31     public Message(String JavaDoc author, String JavaDoc source) {
32         s = "<" + (new java.util.Date JavaDoc(System.currentTimeMillis())).toString() + "> <" + author + "> " + source;
33         if (!(s.endsWith("\n")))
34             s += "\n";
35     }
36     
37     /**
38      * Returns the String corresponding to the Message
39      */

40     public String JavaDoc toString() {
41         return s;
42     }
43 }
44
Popular Tags