KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jt > examples > patterns > Addition


1
2
3 package Jt.examples.patterns;
4 import java.util.*;
5 import java.lang.reflect.*;
6 import java.beans.*;
7 import java.io.*;
8 import Jt.*;
9
10 /**
11  * Add two numbers
12  */

13
14 public class Addition extends JtObject {
15
16
17
18
19   public Addition () {
20   }
21
22
23
24
25   /**
26     * Process object messages.
27     */

28
29   public Object JavaDoc processMessage (Object JavaDoc event) {
30
31    String JavaDoc msgid = null;
32    JtMessage e = (JtMessage) event;
33    Object JavaDoc content;
34    Object JavaDoc data;
35    int op1, op2;
36
37
38      if (e == null)
39     return null;
40
41      msgid = (String JavaDoc) e.getMsgId ();
42
43      if (msgid == null)
44     return null;
45
46      content = e.getMsgContent();
47      data = e.getMsgData ();
48
49      op1 = ((Integer JavaDoc) content).intValue ();
50
51      op2 = ((Integer JavaDoc) data).intValue ();
52
53      if (msgid.equals ("ADD")) {
54        return (new Integer JavaDoc (op1 + op2));
55      }
56
57
58      if (msgid.equals ("JtREMOVE")) {
59        return (null);
60      }
61
62 /*
63      if (this.getObjSuccessor() != null) {
64        sendMessage (this.getObjSuccessor(), event);
65      }
66 */

67      handleError ("Addition.processMessage: invalid message id:" + msgid);
68      return (null);
69
70   }
71
72  
73
74
75 }
76
77
78
Popular Tags