KickJava   Java API By Example, From Geeks To Geeks.

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


1 package Jt.examples.patterns;
2 import java.util.*;
3 import java.lang.reflect.*;
4 import java.beans.*;
5 import java.io.*;
6 import Jt.*;
7
8
9
10 /**
11  * Demonstrates the use of the State pattern (see Flyweight.java).
12  */

13
14
15
16 public class OnSwitch extends JtState {
17
18
19
20   public OnSwitch () {
21   }
22
23
24
25
26   /**
27     * Process object messages.
28     * <ul>
29     * </ul>
30     * @param event Jt Message
31     */

32
33   public Object JavaDoc processMessage (Object JavaDoc event) {
34
35    String JavaDoc msgid = null;
36    JtMessage e = (JtMessage) event;
37    Object JavaDoc content;
38    Object JavaDoc data;
39    JtMessage aux;
40
41
42      if (e == null)
43     return null;
44
45      msgid = (String JavaDoc) e.getMsgId ();
46
47      if (msgid == null)
48     return null;
49
50      content = e.getMsgContent();
51
52      if (msgid.equals ("JtREMOVE")) {
53        return (this);
54      }
55
56      if (msgid.equals ("JtSWITCH_VALUE")) {
57        return ("On");
58      }
59      handleError ("processMessage: invalid message id:" + msgid);
60      return (null);
61
62   }
63
64  
65 }
66
Popular Tags