-
Notifications
You must be signed in to change notification settings - Fork 4
/
RequestsPage.java
232 lines (202 loc) · 9.52 KB
/
RequestsPage.java
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
/**
* This class is the graphical implementation of the make Requests page. On this page, customers can select the type
* of request they want to make and then describe the details of the request. Depending on the request type, the request
* is sent to a different actor in the system (e.g., meeting request to admin, system changes to maintenance, etc.).
*/
public class RequestsPage extends JFrame implements ActionListener
{
// Constants
static final int WIDTH = 1920;
static final int LENGTH = 1080;
// Objects
BankAutomated BA;
HomePage home;
CA customer;
// GUI Components for RequestsPage
private final JComboBox<String> selectType;
private final JButton backToHome;
private final JButton completeButton;
private final JTextArea detailsField;
/**
* RequestsPage Constructor
* @param BA BankAutomated object, to process the logout if the customer terminates the program on this page
* @param home HomePage object, for the customer to return to when they are done making a request
* @param customer CA object, the customer that is currently logged in
*/
public RequestsPage(BankAutomated BA, HomePage home, CA customer)
{
// Set title of the frame
this.setTitle("Make a Request");
this.setLayout(null);
this.home = home;
this.customer = customer;
this.BA = BA;
// GUI Components
Font labels = new Font("Raleway", Font.BOLD, 30);
Border emptyBorder = BorderFactory.createEmptyBorder();
Border border = BorderFactory.createLineBorder(Color.BLACK, 2);
// GUI Components for request type
JLabel requestType = new JLabel("Type of Request:");
requestType.setFont(labels);
requestType.setBorder(emptyBorder);
requestType.setForeground(Color.black);
requestType.setBounds(200,150,300,40);
this.add(requestType);
// GUI Components for request details
String[] accounts = {"Select Request Type", "Request System Changes", "Request Meeting with Admin",
"Request Support from Customer Service"};
selectType = new JComboBox<>(accounts);
selectType.setFont(new Font("Arial", Font.PLAIN, 20));
selectType.setBounds(600, 150, 500, 40);
selectType.setCursor(new Cursor(Cursor.HAND_CURSOR));
selectType.addActionListener(this);
this.add(selectType);
String instructions = "Enter the details of your request here. If requesting a meeting, make\nsure to " +
"include a few dates/timings for the admins to pick one, as well as\nyour preferred meeting setting" +
" (in-person or virtual)\nPlease clear this box before adding your details.";
detailsField = new JTextArea(instructions);
detailsField.setFont(new Font("SansSerif", Font.PLAIN, 22));
detailsField.setBackground(Color.white);
detailsField.setForeground(Color.BLACK);
detailsField.setBounds(300, 210, 700, 300);
// Scroll pane for details field
JScrollPane scroll = new JScrollPane(detailsField);
scroll.setBounds(300, 210, 700, 300);
scroll.setBorder(border);
detailsField.setEditable(true);
this.add(scroll);
// GUI Components for complete button
completeButton = new JButton("Submit Request");
completeButton.setFont(new Font("SansSerif", Font.PLAIN, 22));
completeButton.setBounds(475, 525, 350, 40);
completeButton.setBackground(Color.black);
completeButton.setForeground(Color.white);
completeButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
completeButton.setBorder(emptyBorder);
completeButton.addActionListener(this);
this.add(completeButton);
// GUI Components for back to home button
backToHome = new JButton("Back to Home");
backToHome.setFont(new Font("SansSerif", Font.PLAIN, 22));
backToHome.setBounds(475, 575, 350, 50);
backToHome.setBackground(Color.white);
backToHome.setForeground(new Color(57, 107, 170));
backToHome.setCursor(new Cursor(Cursor.HAND_CURSOR));
backToHome.setContentAreaFilled(false);
backToHome.setFocusPainted(false);
backToHome.setBorder(emptyBorder);
backToHome.setContentAreaFilled(false);
backToHome.addActionListener(this);
this.add(backToHome);
// Window listener for closing the window, logout and exit
this.addWindowListener(new WindowEventHandler() {
@Override
public void windowClosing(WindowEvent evt) {
//BA.logout (logic.logout) would be called here
//Write all changes to the file
BA.logout();
Window[] windows = Window.getWindows();
for (Window window : windows) {
window.dispose();
}
System.exit(0);
}
});
// Frame settings
this.getContentPane().setBackground(Color.white);
this.getRootPane().setDefaultButton(completeButton);
this.setSize(WIDTH, LENGTH);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(false);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
/**
* paint method, overrides the JFrame paint method in order to allow for custom graphical design
* @param g Graphics object
*/
public void paint(Graphics g)
{
super.paint(g);
// Background colour
Graphics2D g2 = (Graphics2D) g;
Color myRed = new Color(230, 30, 30);
Color myBlack = new Color(160, 32, 32);
GradientPaint redToBlack = new GradientPaint(0, 0, myRed, 0, 150, myBlack);
g2.setPaint(redToBlack);
g2.fillRect(0, 0, WIDTH+1, 150);
// Font
Font regFont = new Font("Raleway", Font.BOLD, 60);
g2.setFont(regFont);
g2.setColor(new Color(250, 185, 60));
g2.drawString("Make a Request", 25, 110);
}
/**
* actionPerformed method (implementing ActionListener). When the "Back To Home" button is clicked, it sends
* the customer back to their homepage. When "Submit Request" is selected, customer report is made into an object
* and saved to their arraylist and to the correct counterpart.
* @param e ActionEvent object, which listens and keeps track of any button clicks
*/
@Override
public void actionPerformed(ActionEvent e)
{
// If back to home button is clicked, go back to home page
if (e.getSource() == backToHome)
{
this.setVisible(false);
home.setVisible(true);
}
// If complete button is clicked, check if all fields are filled out
else if (e.getSource() == completeButton)
{
String requestDescription = detailsField.getText();
if (requestDescription.equals("") || requestDescription.contains("Enter the details of your request here.")
|| requestDescription.contains("If requesting a meeting")
|| requestDescription.contains("Please clear this box before adding your details."))
{
JOptionPane.showMessageDialog(this, "Please clear the text box and add details" +
" to your request before submitting.");
}
// Check if request type is selected
else if (selectType.getSelectedIndex()==0)
{
JOptionPane.showMessageDialog(this, "Please select request type before submitting.");
}
// If all fields are filled out, make request
else
{
String selectedType = String.valueOf(selectType.getSelectedItem());
switch (selectedType)
{
case "Request System Changes":
JOptionPane.showMessageDialog(this, "Thank you for making a request to" +
" make our system better. Here at BCS, we strive\nto keep our customers satisfied. Our " +
"maintenance team will look into your request\nshortly.");
BA.makeRequest(customer, "1", requestDescription);
break;
case "Request Meeting with Admin":
JOptionPane.showMessageDialog(this, "Thank you for making a request to" +
" meet an admin. An admin will review it and\ncontact you shortly as per your notification" +
" preferences.");
BA.makeRequest(customer, "2", requestDescription);
break;
case "Request Support from Customer Service":
JOptionPane.showMessageDialog(this, "Thank you for making a request to" +
"get support from customer service. An customer service representative\nwill review it and " +
"contact you shortly as per your notification preferences.");
BA.makeRequest(customer, "3", requestDescription);
break;
default:
System.out.println("ERROR: Something went wrong.");
}
this.setVisible(false);
home.setVisible(true);
}
}
}
}