Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 제목:inner Class를 이용한 동적함수처리
- * 작성자: 박성완(adsloader@naver.com)
- * 목적 : 예제
- * */
- import java.util.HashMap;
- class Event{
- public int STATE = 0;
- public Event (int i ){STATE = i;}
- }
- public class Main {
- public static int START = 0;
- public static int STOP = 1;
- public static int PAUSE = 2;
- //----------------------------------------------------
- public void OnStart(Event e)
- {
- System.out.println("Start");
- }
- public void OnStop(Event e)
- {
- System.out.println("Stop");
- }
- public void OnPause(Event e)
- {
- System.out.println("Pause");
- }
- //----------------------------------------------------
- HashMap m = new HashMap();
- public void Process(Event e)
- {
- FSM f = (FSM)m.get(e.STATE);
- f.Execute(e);
- }
- public Main()
- {
- initProcess();
- }
- public void initProcess()
- {
- m.put(START,
- new FSM(){
- public void Execute(Event e){
- OnStart(e);
- };
- }
- );
- m.put(STOP,
- new FSM(){
- public void Execute(Event e){
- OnStop(e);
- };
- }
- );
- m.put(PAUSE,
- new FSM(){
- public void Execute(Event e){
- OnPause(e);
- };
- }
- );
- }
- class FSM
- {
- public void Execute(Event e){};
- }
- //-----------------------------------------------------
- static public void main(String[] args)
- {
- Main o = new Main();
- o.Process(new Event(Main.START));
- o.Process(new Event(Main.STOP));
- o.Process(new Event(Main.PAUSE));
- }
- }
Add Comment
Please, Sign In to add comment