-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayFirst.java
More file actions
87 lines (70 loc) · 3.07 KB
/
DisplayFirst.java
File metadata and controls
87 lines (70 loc) · 3.07 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
public class DisplayFirst implements DisplayBehavior {
/*
Creates/display the behavior of window(how it looks/fields of user input)
Contains all the user input which we will use to create the email to be sent out
*/
public void display() {
JFrame frame = new JFrame("Campus Security");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setLocation(430, 100);
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
frame.add(panel);
JLabel lbl = new JLabel("Select one of the templates and click OK");
lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
panel.add(lbl);
String[] templates = {"select", "Weather Alert", "Burglary", "Suspicious Activity"};
final JComboBox<String> cb = new JComboBox<String>(templates);
cb.setMaximumSize(cb.getPreferredSize());
cb.setAlignmentX(Component.CENTER_ALIGNMENT);
panel.add(cb);
JLabel lbl2 = new JLabel("Do you want to generate a map?");
lbl2.setAlignmentX(Component.CENTER_ALIGNMENT);
panel.add(lbl2);
String[] Answers = {"select", "Yes", "No"};
final JComboBox<String> cb1 = new JComboBox<String>(Answers);
cb1.setMaximumSize(cb.getPreferredSize());
cb1.setAlignmentX(Component.CENTER_ALIGNMENT);
panel.add(cb1);
JButton btn = new JButton("OK");
btn.setAlignmentX(Component.CENTER_ALIGNMENT);
panel.add(btn);
frame.setVisible(true);
/*
adding action listener for button "ok"
to create a new WindowAddress if the user choose for
a map to be generate or not, if not then it creates a new WindowTemplate
and which behavior is set depends on the incident.
*/
btn.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
frame.dispose();
String mapSelection = (String)cb1.getSelectedItem();
String incidentSelected = (String)cb.getSelectedItem();
String address;
if(mapSelection == "Yes"){
try {
Window map = new WindowAddress(incidentSelected);
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
else{
try {
Window incident = new WindowTemplates(incidentSelected);
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
}
});
}
}