Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Submit Button Listener
- submitButton.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent ae){
- boolean notDuplicated = false;
- String id = studentIDField.getText();
- String username = userNameField.getText();
- String password = passwordField.getText();
- boolean idValid = id.matches("\\d{5,6}");
- boolean usernameValid = username.matches("[A-Za-z][A-Za-z0-9]*@[A-Za-z][A-Za-z0-9]*\\.(com|edu|org)");
- boolean passwordValid = password.matches("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[~!#$])[A-Za-z0-9~!#$]{8,}$");
- for (Student student : studentsList) {
- if (username.equals(student.getUsername())) {
- notDuplicated = true;
- }
- }
- if (notDuplicated) {
- JOptionPane.showMessageDialog(rootPane, "Username already taken!");
- userNameField.setText("");
- }
- if (!idValid) {
- JOptionPane.showMessageDialog(rootPane, "Please enter a valid user ID!");
- studentIDField.setText("");
- }
- if (!usernameValid) {
- JOptionPane.showMessageDialog(rootPane, "Please enter a valid username!");
- userNameField.setText("");
- }
- if (!passwordValid) {
- JOptionPane.showMessageDialog(rootPane, "Please enter a valid password!");;
- passwordField.setText("");
- }
- if (notDuplicated == false && idValid == true && usernameValid == true && passwordValid == true) {
- for (Student student : studentsList) {
- if (id == student.getId()) {
- student.setUsername(username);
- student.setPassword(password);
- }
- }
- JOptionPane.showMessageDialog(rootPane, "Student account added!");
- studentIDField.setText("");
- userNameField.setText("");
- passwordField.setText("");
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement