forked from alexs2112/Scholarship-Thing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewUser.java
140 lines (122 loc) · 4.16 KB
/
NewUser.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
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.io.*;
import java.util.*;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.awt.Font;
public class NewUser extends JFrame {
private static final long serialVersionUID = 1060623638149583738L;
private JPanel contentPane;
private JTextField textField;
private JLabel lblNewLabel_1;
private JTextField textField_1;
private JTextField textField_2;
private JLabel lblPassword;
private JComboBox comboBox;
private JButton btnNewButton;
private JLabel lblNewLabel_2;
private JLabel lblNewLabel_3;
private JButton btnNewButton_1;
//private Data data;
/**
* Create the frame.
*/
public NewUser(Data data) {
//design elements
setTitle("University of Calgary Scholarship Application System | New User");
setBounds(100, 100, 750, 500);
contentPane = new JPanel();
contentPane.setBackground(Color.ORANGE);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
textField = new JTextField();
textField.setBounds(296, 83, 130, 26);
contentPane.add(textField);
textField.setColumns(10);
//name of user
JLabel lblNewLabel = new JLabel("Name:");
lblNewLabel.setBounds(156, 88, 115, 16);
contentPane.add(lblNewLabel);
//account username
lblNewLabel_1 = new JLabel("Username:");
lblNewLabel_1.setBounds(156, 135, 115, 16);
contentPane.add(lblNewLabel_1);
//account password
lblPassword = new JLabel("Password:");
lblPassword.setBounds(156, 182, 115, 16);
contentPane.add(lblPassword);
textField_1 = new JTextField();
textField_1.setBounds(296, 130, 130, 26);
contentPane.add(textField_1);
textField_1.setColumns(10);
textField_2 = new JTextField();
textField_2.setBounds(296, 177, 130, 26);
contentPane.add(textField_2);
textField_2.setColumns(10);
//type of user
String[] roleBox = {"Administrator", "Coordinator", "Professor"};
comboBox = new JComboBox(roleBox);
comboBox.setBounds(296, 219, 130, 27);
contentPane.add(comboBox);
//action handler for save button
btnNewButton = new JButton("Save");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//if any textfields are left empty
if (textField.getText().equals("") || textField_1.getText().equals("") || textField_2.getText().equals("")) {
JOptionPane.showMessageDialog(null, "Please ensure all fields are complete");
//otherwise, create new user with above details
}else {
String name = textField.getText();
String username = textField_1.getText();
String password = textField_2.getText();
String role = comboBox.getSelectedItem().toString();
String convertedRole;
if (role == "Administrator")
convertedRole = "admin";
else if (role == "Coordinator")
convertedRole = "sc";
else if (role == "Professor")
convertedRole = "prof";
else
convertedRole = "ERROR";
//add new user to database, save and close
User newUser = new User(name, convertedRole, username, password);
data.addUser(newUser);
data.saveData();
dispose();
}
}
});
btnNewButton.setBounds(381, 318, 117, 29);
contentPane.add(btnNewButton);
lblNewLabel_2 = new JLabel("University of Calgary Scholarship Application System");
lblNewLabel_2.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 18));
lblNewLabel_2.setBounds(113, 6, 477, 20);
contentPane.add(lblNewLabel_2);
lblNewLabel_3 = new JLabel("Role:");
lblNewLabel_3.setBounds(156, 226, 92, 20);
contentPane.add(lblNewLabel_3);
//brings user to previous screen
btnNewButton_1 = new JButton("Cancel");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
btnNewButton_1.setBounds(212, 318, 117, 29);
contentPane.add(btnNewButton_1);
}
}