-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRealtimeUpdate.java
More file actions
77 lines (58 loc) · 1.78 KB
/
Copy pathRealtimeUpdate.java
File metadata and controls
77 lines (58 loc) · 1.78 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package Models;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Method;
import javax.swing.Timer;
/**
*
* This class handles real-time updates for online users.
*
* It uses a Timer to periodically invoke a specified method.
*
*
*
* @author Yohan Silva
*
*/
public class RealtimeUpdate {
private Timer timer;
/**
*
* Starts the timer to update online users.
*
*
*
* @param ok The method to be invoked every 5 seconds.
*
* @param target The object on which the method should be invoked.
*
*/
public void startOnlineUserUpdates(Method ok, Object target) {
timer = new Timer(5000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
// Invoke the method passed as a parameter
ok.invoke(target);
} catch (Exception ex) {
ex.printStackTrace(); // Handle exceptions appropriately
}
}
});
timer.start();
}
}
// We can access this model configuration
//-------------------------------------------------------
// private void startOnlineUserUpdates() {
// rt = new RealtimeUpdate();
// try {
// // Get the method reference for onlineUser
// Method onlineUserMethod;
// onlineUserMethod = AdminMainDash.class.getDeclaredMethod("onlineUser");
// // Start online user updates
// rt.startOnlineUserUpdates(onlineUserMethod, this);
// } catch (NoSuchMethodException e) {
// e.printStackTrace();
// }
// }