Guest User

Untitled

a guest
Mar 13th, 2018
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. /*
  2. * 제목:inner Class를 이용한 동적함수처리
  3. * 작성자: 박성완(adsloader@naver.com)
  4. * 목적 : 예제
  5. * */
  6.  
  7. import java.util.HashMap;
  8.  
  9. class Event{
  10. public int STATE = 0;
  11. public Event (int i ){STATE = i;}
  12. }
  13.  
  14. public class Main {
  15. public static int START = 0;
  16. public static int STOP = 1;
  17. public static int PAUSE = 2;
  18.  
  19. //----------------------------------------------------
  20. public void OnStart(Event e)
  21. {
  22. System.out.println("Start");
  23. }
  24.  
  25. public void OnStop(Event e)
  26. {
  27. System.out.println("Stop");
  28. }
  29.  
  30. public void OnPause(Event e)
  31. {
  32. System.out.println("Pause");
  33. }
  34.  
  35. //----------------------------------------------------
  36. HashMap m = new HashMap();
  37.  
  38. public void Process(Event e)
  39. {
  40. FSM f = (FSM)m.get(e.STATE);
  41. f.Execute(e);
  42. }
  43.  
  44. public Main()
  45. {
  46. initProcess();
  47. }
  48.  
  49. public void initProcess()
  50. {
  51. m.put(START,
  52. new FSM(){
  53. public void Execute(Event e){
  54. OnStart(e);
  55. };
  56. }
  57. );
  58.  
  59. m.put(STOP,
  60. new FSM(){
  61. public void Execute(Event e){
  62. OnStop(e);
  63. };
  64. }
  65. );
  66.  
  67.  
  68. m.put(PAUSE,
  69. new FSM(){
  70. public void Execute(Event e){
  71. OnPause(e);
  72. };
  73. }
  74. );
  75. }
  76.  
  77. class FSM
  78. {
  79. public void Execute(Event e){};
  80. }
  81. //-----------------------------------------------------
  82. static public void main(String[] args)
  83. {
  84. Main o = new Main();
  85. o.Process(new Event(Main.START));
  86. o.Process(new Event(Main.STOP));
  87. o.Process(new Event(Main.PAUSE));
  88.  
  89. }
  90. }
Add Comment
Please, Sign In to add comment