01 package rtype;
02
03 import java.util.ArrayList;
04
05 public class EventManager {
06
07 //Singleton variable and methods:
08 private EventManager(){};
09 private static EventManager instance;
10 public static EventManager instance()
11 {
12 if (instance == null)
13 instance = new EventManager();
14 return instance;
15 }
16
17
18 private ArrayList<KeyListener> listeners = new ArrayList<KeyListener>();
19
20 public void addListener(int key,KeyListener listener)
21 {
22 listener.setKeyMonitored(key);
23 listeners.add(listener);
24 }
25
26 public void removeListener(KeyListener listener)
27 {
28 listeners.remove(listener);
29 }
30
31 public void clear()
32 {
33 listeners.clear();
34 }
35
36 void checkEvents()
37 {
38 for(KeyListener listener: listeners)
39 {
40 listener.checkKey();
41 }
42 }
43 }
|