-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
92 lines (74 loc) · 3.15 KB
/
Main.java
File metadata and controls
92 lines (74 loc) · 3.15 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Main extends JFrame implements ActionListener {
private JMenuItem startMenuItem, stopMenuItem, configureMenuItem;
private Blackboard blackboard;
private WorkArea workArea;
private Server server;
private Thread serverThread;
public Main() {
setTitle("Eye Tracking Simulator");
setSize(800, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create menu bar
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Options");
startMenuItem = new JMenuItem("Start");
stopMenuItem = new JMenuItem("Stop");
configureMenuItem = new JMenuItem("Configure");
menu.add(startMenuItem);
menu.add(stopMenuItem);
menu.add(configureMenuItem);
menuBar.add(menu);
setJMenuBar(menuBar);
startMenuItem.addActionListener(this);
stopMenuItem.addActionListener(this);
configureMenuItem.addActionListener(this);
stopMenuItem.setEnabled(false); // Disable Stop initially
blackboard = Blackboard.getInstance();
workArea = new WorkArea(blackboard);
add(workArea);
server = new Server(blackboard);
serverThread = new Thread(server);
serverThread.start(); // Start the server (keeps it alive)
}
public static void main(String[] args) {
Main app = new Main();
app.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == startMenuItem) {
startTracking();
} else if (e.getSource() == stopMenuItem) {
stopTracking();
} else if (e.getSource() == configureMenuItem) {
configureSettings();
}
}
private void startTracking() {
startMenuItem.setEnabled(false);
stopMenuItem.setEnabled(true);
configureMenuItem.setEnabled(false);
blackboard.startTracking(); // Update tracking status on blackboard
server.startTransmission(); // Start data transmission
}
private void stopTracking() {
startMenuItem.setEnabled(true);
stopMenuItem.setEnabled(false);
configureMenuItem.setEnabled(true);
blackboard.stopTracking(); // Stop tracking, but server keeps running
server.stopTransmission(); // Stop transmission but don't shut down the server
}
private void configureSettings() {
String widthStr = JOptionPane.showInputDialog(this, "Enter width:", "Configure", JOptionPane.QUESTION_MESSAGE);
String heightStr = JOptionPane.showInputDialog(this, "Enter height:", "Configure", JOptionPane.QUESTION_MESSAGE);
String speedStr = JOptionPane.showInputDialog(this, "Enter data transmission speed (frames per second):", "Configure", JOptionPane.QUESTION_MESSAGE);
int width = Integer.parseInt(widthStr);
int height = Integer.parseInt(heightStr);
int speed = Integer.parseInt(speedStr);
setSize(width, height);
blackboard.setTransmissionSpeed(speed); // Update the transmission speed in the blackboard
}
}