-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvisibleCloak_frontend.java
More file actions
80 lines (59 loc) · 2.22 KB
/
InvisibleCloak_frontend.java
File metadata and controls
80 lines (59 loc) · 2.22 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
package frontend;
import backend.InvisibleCloakEngine;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class InvisibleCloakGUI extends JFrame implements ActionListener {
JButton startBtn, stopBtn, colorBtn;
JLabel videoLabel, statusLabel;
InvisibleCloakEngine engine;
public InvisibleCloakGUI() {
setTitle("Invisible Cloak - OpenCV");
setSize(900, 650);
setLayout(new BorderLayout());
// ---------- TOP PANEL ----------
JPanel topPanel = new JPanel(new FlowLayout());
startBtn = new JButton("Start Camera");
stopBtn = new JButton("Stop Camera");
colorBtn = new JButton("Red Cloak");
startBtn.addActionListener(this);
stopBtn.addActionListener(this);
colorBtn.addActionListener(this);
topPanel.add(startBtn);
topPanel.add(stopBtn);
topPanel.add(colorBtn);
add(topPanel, BorderLayout.NORTH);
// ---------- VIDEO PANEL ----------
videoLabel = new JLabel("Camera Feed");
videoLabel.setHorizontalAlignment(JLabel.CENTER);
videoLabel.setOpaque(true);
videoLabel.setBackground(Color.BLACK);
add(videoLabel, BorderLayout.CENTER);
// ---------- STATUS BAR ----------
statusLabel = new JLabel("Status: Ready");
statusLabel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
add(statusLabel, BorderLayout.SOUTH);
// ---------- BACKEND ENGINE ----------
engine = new InvisibleCloakEngine(videoLabel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == startBtn) {
statusLabel.setText("Status: Starting camera (step away for 3 sec)");
engine.startCamera();
}
if (e.getSource() == stopBtn) {
statusLabel.setText("Status: Camera stopped");
engine.stopCamera();
}
if (e.getSource() == colorBtn) {
statusLabel.setText("Cloak color: RED");
}
}
public static void main(String[] args) {
new InvisibleCloakGUI();
}
}