-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWelcomePanel.java
executable file
·247 lines (215 loc) · 8.06 KB
/
WelcomePanel.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
package se115.master;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileReader;
class WelcomePanel {
private JFrame frame;
private JPanel content;
/**
* Constructor is called automatically
* when WelcomePanel object is initialized.
* It contains content pane, information placed on pane
* and register button.
*/
public WelcomePanel() {
// Outer panel
content = new JPanel();
content.setBorder(new TitledBorder(new LineBorder(Color.blue,5),
"<html><h1>Student Control Panel</h1></html>"));
content.setLayout(null);
// Messages that will be printed on page
String welcomeMessage1 = " Welcome to Student Console\n";
String welcomeMessage2 = "You can create things below:\n";
String welcomeMessage3 = "Schedule, Assignments and Exam Dates\n";
String welcomeMessage4 = " Please click the Register button";
// Creating new Panel for messages
JPanel msgPanel = new JPanel();
msgPanel.setBounds(25,50,550,300);
msgPanel.setLayout(new GridLayout(3,1));
String[] messageHolder = {welcomeMessage1, welcomeMessage2, welcomeMessage3, welcomeMessage4};
JLabel row1 = new JLabel();
JLabel row2 = new JLabel();
JLabel row3 = new JLabel();
JLabel row4 = new JLabel();
JLabel[] labelHolder = {row1,row2,row3,row4};
// Panel for providing gray area to seem better
JPanel grayPanel = new JPanel();
grayPanel.setBackground(Color.gray);
grayPanel.setLayout(new GridLayout(2,1));
// Adding message on the page
int counter = 0;
for (JLabel j : labelHolder) {
if(counter == 1 || counter == 2) {
j.setText(messageHolder[counter]);
j.setFont(new Font("Serif", Font.BOLD, 30));
grayPanel.add(j);
counter++;
continue;
} else {
j.setText(messageHolder[counter]);
j.setFont(new Font("Serif", Font.BOLD, 30));
msgPanel.add(j);
}
counter++;
if(counter == 1) {
msgPanel.add(grayPanel);
}
}
content.add(msgPanel);
// Adding register button
JPanel btnPanel = new JPanel();
btnPanel.setBounds(245, 400, 110, 50);
btnPanel.setLayout(null);
Color myColor = new Color(255,70, 0);
btnPanel.setBackground(myColor);
JButton registerBtn = new JButton("Register");
registerBtn.setBounds(5,5,100,40);
registerBtn.addActionListener(new RegisterBtnListener()); // Adding action when the button is clicked
btnPanel.add(registerBtn);
content.add(btnPanel);
}
/**
* Creating a frame that contains content pane.
*/
public void getWelcomeFrame() {
frame = new JFrame("IEU");
frame.setContentPane(content);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setSize(600, 500);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);
}
/**
* Check string.
* If there is number in string, return false;
* if there is no number, return true.
*/
private static boolean isStringCorrect(String word) {
String invalidChars = "0123456789!#$%&'()*+,-./:;<=>?@[]^_`{|}~";
String validChars = "ABCÇDEFGĞHIİJKLMNOÖPQRSŞTUÜVWXYZabcçdefgğhıijklmnoöpqrsştuüvwxyz";
for (int i = 0; i < invalidChars.length(); i++) {
if (word.contains(Character.toString(invalidChars.charAt(i)))) {
return false;
}
}
// if and only if word contains one of valid character then method will return true
for(int i = 0; i < validChars.length(); i++) {
if(word.contains(Character.toString(validChars.charAt(i)))) {
return true;
}
}
return false;
}
/**
* Checking number if it has a string.
* If there is a string in numbers, return false;
* if there is no string, return true.
*/
private static boolean isNumberCorrect(String number) {
String invalidChars = " !#$%&'()*+,-./:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~";
for (int i = 0; i < invalidChars.length(); i++) {
if (number.contains(Character.toString(invalidChars.charAt(i)))) {
return false;
}
}
return true;
}
/**
* Check registration inputs.
* if there is empty input, return false;
* if there is no empty input, return true.
*/
private static boolean controlRegInfo(String data) {
if(data.isEmpty()) {
return false;
} else {
return true;
}
}
/**
* all registration transactions are happening in that method
* @param frame for closing current frame
*/
public static void signUp(JFrame frame) {
frame.setVisible(false);
Registration r = new Registration();
// Checking whether there is any missing information or not
int counter1 = 0;
int counter2 = 0;
int counter3 = 0;
while (r.isDone()) {
if(counter1 == 0) {
r.inputNameSurname();
if (!controlRegInfo(r.getNameSurname())) {
JOptionPane.showMessageDialog(null, "Name Surname is Empty"
, "Error Message", JOptionPane.WARNING_MESSAGE);
continue;
} else if (!isStringCorrect(r.getNameSurname())) {
JOptionPane.showMessageDialog(null, "Name Surname is Invalid"
, "Error Message", JOptionPane.WARNING_MESSAGE);
continue;
}
}
counter1 = 1;
if(counter2 == 0) {
r.inputNumber();
if (!isNumberCorrect(r.getNumber())) {
JOptionPane.showMessageDialog(null, "Number is Invalid"
, "Error Message", JOptionPane.WARNING_MESSAGE);
continue;
} else if (!controlRegInfo(r.getNumber())) {
JOptionPane.showMessageDialog(null, "Number is Empty"
, "Error Message", JOptionPane.WARNING_MESSAGE);
continue;
}
}
counter2 = 1;
if(counter3 == 0) {
r.inputDepartment();
if (!controlRegInfo(r.getDepartment())) {
JOptionPane.showMessageDialog(null, "Department is Empty"
, "Error Message", JOptionPane.WARNING_MESSAGE);
continue;
} else if (!isStringCorrect(r.getDepartment())) {
JOptionPane.showMessageDialog(null, "Department is Invalid"
, "Error Message", JOptionPane.WARNING_MESSAGE);
continue;
}
}
counter3 = 1;
r.setDone(false); // Stop while loop
}
r.setContent();
r.setRegisterFrame();
}
public boolean isPreviousUser() {
try {
FileReader fileReader = new FileReader("users.txt");
BufferedReader reader = new BufferedReader(fileReader);
String line = null;
line = reader.readLine();
if(line == null) {
return false;
} else {
return true;
}
} catch(Exception ex) {
ex.printStackTrace();
}
return false;
}
/**
* Inner class which provide action for Register button
*/
private class RegisterBtnListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
signUp(frame);
}
}
}