-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuiElement.java
More file actions
48 lines (38 loc) · 1.26 KB
/
Copy pathGuiElement.java
File metadata and controls
48 lines (38 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package work4;
import java.util.ArrayList;
import java.util.List;
public abstract class GuiElement {
protected int id;
protected String name;
protected boolean visible;
// Список спостерігачів
private List<EventListener> listeners = new ArrayList<>();
public GuiElement(int id, String name) {
this.id = id;
this.name = name;
this.visible = true;
}
public void show() {
this.visible = true;
System.out.println("Елемент [" + name + "] відображено.");
}
public void hide() {
this.visible = false;
System.out.println("Елемент [" + name + "] приховано.");
}
public void addListener(EventListener listener) {
listeners.add(listener);
}
public void removeListener(EventListener listener) {
listeners.remove(listener);
}
protected void notifyListeners(String eventType) {
System.out.println(">>> Подія '" + eventType + "' на елементі [" + name + "]");
for (EventListener listener : listeners) {
listener.handleEvent(eventType, this);
}
}
public String getName() {
return name;
}
}